2017-05-04 118 views
0

连接我有一个以这种方式编码的联系表格:我怎么能联系表单与电子邮件与PHP

HTML代码

<form enctype="text/plain" action="send_form_email.php" method="post" role="form"> 
<div class="col-md-1 col-sm-1"></div> 
<div class="col-md-10 col-sm-10"> 
<div class="col-md-6 col-sm-6"> 
<input name="Emri" type="text" class="form-control" id="name" placeholder="Emri"> 
</div> 
<div class="col-md-6 col-sm-6"> 
<input name="Email" type="email" class="form-control" id="email" placeholder="Email"> 
</div> 
<div class="col-md-12 col-sm-12"> 
<input name="Sbjekti" type="text" class="form-control" id="subject" placeholder="Subjekti"> 
</div> 
<div class="col-md-12 col-sm-12"> 
<textarea name="Msazhi" rows="5" class="form-control" id="message" placeholder="Mesazhi"></textarea> 
</div> 
<div class="col-md-6 col-sm-6"> 
<input name="Dergo" type="submit" class="form-control" id="submit" value="DERGO"> 
</div> 
</div> 
<div class="col-md-1 col-sm-1"></div> 
</form> 

我与调用的PHP代码连接它send_form_email.php

PHP代码

<?php 
if(isset($_POST['email'])) { 

    // EDIT THE 2 LINES BELOW AS REQUIRED 
    $email_to = "[email protected]"; 
    $email_subject = "Your email subject line"; 

    function died($error) { 
     // your error code can go here 
     echo "We are very sorry, but there were error(s) found with the form you submitted. "; 
     echo "These errors appear below.<br /><br />"; 
     echo $error."<br /><br />"; 
     echo "Please go back and fix these errors.<br /><br />"; 
     die(); 
    } 


    // validation expected data exists 
    if(!isset($_POST['first_name']) || 
     !isset($_POST['last_name']) || 
     !isset($_POST['email']) || 
     !isset($_POST['telephone']) || 
     !isset($_POST['comments'])) { 
     died('We are sorry, but there appears to be a problem with the form you submitted.');  
    } 
    $first_name = $_POST['first_name']; // required 
    $last_name = $_POST['last_name']; // required 
    $email_from = $_POST['email']; // required 
    $telephone = $_POST['telephone']; // not required 
    $comments = $_POST['comments']; // required 

    $error_message = ""; 
    $email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; 
    if(!preg_match($email_exp,$email_from)) { 
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; 
    } 
    $string_exp = "/^[A-Za-z .'-]+$/"; 
    if(!preg_match($string_exp,$first_name)) { 
    $error_message .= 'The First Name you entered does not appear to be valid.<br />'; 
    } 

    if(!preg_match($string_exp,$last_name)) { 
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; 
    } 

    if(strlen($comments) < 2) { 
    $error_message .= 'The Comments you entered do not appear to be valid.<br />'; 
    } 

    if(strlen($error_message) > 0) { 
    died($error_message); 
    } 

    $email_message = "Form details below.\n\n"; 


    function clean_string($string) { 
     $bad = array("content-type","bcc:","to:","cc:","href"); 
     return str_replace($bad,"",$string); 
    } 



    $email_message .= "First Name: ".clean_string($first_name)."\n"; 
    $email_message .= "Last Name: ".clean_string($last_name)."\n"; 
    $email_message .= "Email: ".clean_string($email_from)."\n"; 
    $email_message .= "Telephone: ".clean_string($telephone)."\n"; 
    $email_message .= "Comments: ".clean_string($comments)."\n"; 

// create email headers 
$headers = 'From: '.$email_from."\r\n". 
'Reply-To: '.$email_from."\r\n" . 
'X-Mailer: PHP/' . phpversion(); 
@mail($email_to, $email_subject, $email_message, $headers); 
?> 

<?php 

} 
?> 

我已经添加了我的电子邮件地址,但这不起作用,当我点击提交时,send_form_email.php正在被下载。 任何人都可以帮我吗?

非常感谢

+0

软件PHP环境卸下'ENCTYPE =“text/plain的”' –

+0

你怎么得到,当你手动打开PHP文件浏览器? –

+0

php文件下载本身 – xhesjana

回答

0

PHP是一种服务器端脚本语言,你在支持PHP的服务器上运行的代码?

如果没有,你可以轻松地设置你与像XAMPP

+0

所以在XAMPP我可能需要创建一个数据库? – xhesjana

+0

@xhesjana不可以,你可以使用XAMPP来运行你的PHP代码,但也许 你会从本地主机发送邮件时遇到一些问题。您也可以尝试托管。你想在哪里部署你的应用程序? –

+0

我会把我的代码在cpanel加速2,实际上我有一个在这个主机的网站,但我想把一个新的设计新的代码。 – xhesjana

相关问题