2012-07-23 36 views
0

我已经创建了一个PHP文件,以便在我的jQuery移动网站上使用我的表单。表格完美地工作,并发送电子邮件和错误的工作和所有。但我不断收到来自(未知发件人)的电子邮件。主题栏和电子邮件信息在那里。 (电子邮件来自主持主机电子邮件地址的表单)。感谢您提供的任何帮助。未知发件人PHP(内部代码)

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

// Here is the email to information 

$email_to = "[email protected]"; 
$email_subject = "Customer Service Form"; 
$email_from = "Company"; 

//error code 

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

if(!isset($_POST['name']) || 
!isset($_POST['email']) || 
!isset($_POST['message'])) { 
    died('We are sorry but there appears to be a problem with the form you submitted.'); 
} 

$name = $_POST['name']; 
$email = $_POST['email']; 
$message = $_POST['message']; 

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

$string_exp = "/^[A-Za-z.'-]+$/"; 
if(!preg_match($string_exp, $name)){ 
    $error_message .= 'The name you entered does not seem to be valid.<br/>'; 
    } 

if(strlen($message) < 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 .= "Name:" . clean_string ($name) . "\n"; 
    $email_message .= "E-Mail:" . clean_string ($email) . "\n"; 
    $email_message .= "Message:" . clean_string ($message) . "\n"; 

    //create email headers 

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

    <!-- Success Message Goes Here --> 
    Thank you for contacting us. We will be in touch with you shortly. <br/> 
    Please Click <a href="contact.html"> here </a> to go back to the contact page. 
    <?php 
} 
?> 
+0

您通常必须从主机购买经过身份验证的邮件...与基本托管软件包(通常)一样多。否则,请转到您的电子邮件地址并添加主持人电子邮件作为联系人。 – Ozzy 2012-07-23 04:17:19

+0

@Ozzy:任何体面的网络主机都应该让你访问他们的SMTP服务器(因为大多数网络主机还提供免费的电子邮件托管)。我从来没有遇到过甚至是共享的网络主机,这些主机要求您购买单独的服务,只需从您的Web应用程序发送交易电子邮件或营销电子邮件(只要它们确认选择列表)即可。 – 2012-07-23 04:26:19

回答

5

From标题格式为:

Display Name <email address> 

例如:

Company <[email protected]> 

现在,你仅仅使用 “公司”,这既不是有效的e邮件地址,最后也没有电子邮件地址。

+0

我的公司部分在我的实际代码中为$ email_from =“Hardy Insurance and Risk Management”;我的代码代码的哪一部分是你告诉我改变(刚开始使用PHP集成到HTML中,对于某些问题抱歉)大约哪一行?谢谢你的帮助! – 2012-07-23 04:45:21

+0

@BrentTroutman:只需在尖括号中添加一个电子邮件地址到名称的末尾。 – casablanca 2012-07-23 05:23:49