0

我正在尝试将表单提交到电子邮件,最终以 gmail 地址结束。但是,我收到返回错误说:

Our_system_has_detected_that_this_message_is/550-5.7.1_not_RFC_2822_compliant._To_reduce_the_amount_of_spam_sent_to_Gmail,/550-5.7.1_this_message_has_been_blocked._Please_review/550_5.7.1_RFC_2822_specifications_for_more_information。w10si875474obo.147 -_gsmtp/

下面的代码,我做错了什么还是我在某处遗漏了错误的代码/语法?:

<?php

    if($_POST) {

        if($_POST["token"]==true){

            $email = $_POST['email'];

            $from_name = 'Whoever';
            $from = 'someemail@whatever.com';

            $to = 'someemail@gmail.com';
            $subject = 'Connect Form';
            $semi_rand = md5(time());
            $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
            $headers = "Date: ". date("r") ."\r\n". "From: ".$from .  "\r\nFrom: ".$from_name." <".$from.">\r\n";
            $headers .= "MIME-Version: 1.0\n" .
                "Content-Type: multipart/mixed;\n" .
                " boundary=\"{$mime_boundary}\"";
            $message_top = "This is a multi-part message in MIME format.\n" .
                "--{$mime_boundary}\n" .
                "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
                "Content-Transfer-Encoding: 7bit\n";

                if(sizeof($_POST['contact_via'])>0)
                    $contact_via=implode(", ", $_POST['contact_via']);
                else
                    $contact_via="";

                $email_message = "\n".'<table cellspacing="4">
                  <tr><td align="right">Contact Name : </td><td>'.$_POST['contact_name'].'</td></tr>
                </table>';

            $email_message = stripslashes($email_message);
            $email_message = str_replace("\n","\n",$email_message);
            $email_message = $message_top . $email_message;

            mail($to, $subject, $email_message, $headers);
            echo '<script>window.location = "http://www.website.com/Thank-You.html";</script>';
          exit;

        }else{
            echo '<script>window.location = "http://www.website.com/Thank-You.html";</script>';
            exit;
        }

    }
?>
4

2 回答 2

4

直接使用mail()是一种挫败感。有很多事情会出错,您必须手动编写附件、HTML 电子邮件支持等内容。

使用SwiftMailer之类的健全的邮件包装器可以让您减少对处理邮件的深奥细节的担忧,并专注于更有用的事情。

在这种特殊情况下,您似乎正在设置重复From:的标题(并且很难在\r\nand之间做出决定\n)。

$headers = "Date: ".date("r")."\r\n" . "From: ".$from . "\nFrom: ".$from_name." <".$from.">\n";

于 2013-12-19T16:12:57.037 回答
2

RFC2822规定了这一点,并且Date:From:电子邮件上的强制性标头字段。

你有这个,但不正确。

试试这个标题行:

$headers = "Date: ". date("r") ."\r\n". "From: $from_name <$from>\r\n";
于 2013-12-19T16:15:57.100 回答