为什么我的php电子邮件表单只发送电子邮件到某些地址?

时间:2013-08-02 01:16:13

标签: php

我有一个通过php提交的联系表单,但是我在将其发送到转发的电子邮件地址时遇到了问题。

我的网站托管在iPage上,iPage上的MX记录指向Hover,我的电子邮件和域名已注册/管理。我只在Hover上设置了电子邮件转发设置(myname@mysite.com,转发到我已经使用多年的电子邮件),它就像一个魅力。发送到myname@mysite.com电子邮件的任何电子邮件都会直接发送到我的收件箱中,以便我永远保存这封电子邮件。

但是,我网站上的php联系表单没有收到我的电子邮件的信息。如果我将“to”字段设置为发送到我永远使用的电子邮件,联系表单会直接将其提交给我的电子邮件。但是,如果我使用myname@mysite.com电子邮件作为“收件人”字段,则联系表单永远不会到达我的收件箱。

这是php文件:

<?php

// get the posted data  
$name = $_POST["name"];  
$band_name = $_POST["band_name"];
$email = $_POST["email"];  
$link = $_POST["link"];
$tracking = $_POST["tracking"];  
$mixing = $_POST["mixing"];
$mastering = $_POST["mastering"];
$reamping = $_POST["reamping"];
$editing = $_POST["editing"];
$other = $_POST["other"];
$comments = $_POST["comments"];
$songs = $_POST["songs"];
$link_fb = $_POST["link_fb"];
$link_yt = $_POST["link_yt"];
$link_db = $_POST["link_db"];

// check that a name was entered  
if (empty($name))  
    $error = "You must enter your name.";  
// check that an email address was entered 
elseif (empty($band_name))
    $error = "You must enter your band's name.";
elseif (empty($email))   
    $error = "You must enter your email address.";  
// check for a valid email address  
elseif (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $email))  
    $error = "You must enter a valid email address.";
elseif (empty($link_fb) && empty($link_yt) && empty($link_db))
    $error = "You must enter a link to for either Facebook, Youtube or Dropbox.";
elseif (empty($tracking) && empty($mixing) && empty($mastering) && empty($reamping) && empty($editing) && empty($other))
    $error = "You must check either tracking, mixing, mastering, editing or other.";
elseif (empty($comments))
    $error = "You must describe your project in detail.";
elseif (empty($songs))
    $error = "You must enter a total song number.";

// check if an error was found - if there was, send the user back to the form  
if (isset($error)) {  
    header("Location: /?e=".urlencode($error)); exit;  
}

// write the email content  
$email_content = "Name: $name\n";  
$email_content .= "Email Address: $email\n";
$email_content .= "Band Name: $band_name\n";
if (!empty($link_fb)) 
    $email_content .= "Facebook Link: $link_fb\n";
if (!empty($link_yt)) 
    $email_content .= "YouTube Link: $link_yt\n";
if (!empty($link_db)) 
    $email_content .= "Dropbox Link: $link_db\n";
$email_content .= "Looking for the following services:\n\n";
if (!empty($tracking)) 
    $email_content .= "\tTracking\n";
if (!empty($mixing)) 
    $email_content .= "\tMixing\n";
if (!empty($mastering)) 
    $email_content .= "\tMastering\n";
if (!empty($reamping)) 
    $email_content .= "\tReamping\n";
if (!empty($editing)) 
    $email_content .= "\tEditing\n";
if (!empty($other)) 
    $email_content .= "\tOther\n\n";
$email_content .= "Songs: $songs\n";
$email_content .= "Comments:\n\n\t$comments";  

// send the email  
mail ("brian@456recordings.com", "Quote Request", $email_content, 'From: 456Recordings.com <webmaster@456recordings.com>' );  

// send the user back to the form  
header("Location: /?s=".urlencode("Thank you for your message.")); exit;  

?>

1 个答案:

答案 0 :(得分:1)

这不是您的代码的问题,这是您输入域名和邮件服务器设置的问题。您需要让您的注册商将您的Web服务器的IP地址添加到您的域的spf记录中。

基本上,当您的电子邮件提供商收到电子邮件时,他们会查找您的域名,并确保发送该电子邮件的IP地址有权发送该域名的电子邮件。如果它无法识别IP地址,则只删除该电子邮件。

你曾经使用过的电子邮件不会使用spf过滤(比如gmail),而你的新电子邮件提供商也会这样做(比如godaddy,1and1,yahoo)。

如果您使用Google SPF和DKIP,您会找到更多信息。

稍作修改,您的注册商是godaddy,这已保存在我的书签中 http://support.godaddy.com/help/article/7926/adding-or-editing-spf-records