电子邮件主题行上的“答复”(使用php邮件)

时间:2018-10-28 23:11:46

标签: php email subject

我使用php邮件为邮件列表设置了简单的电子邮件,并使用我发现的教程使用边界以纯文本格式和html格式发送邮件。

一切正常,但主题行显示为

下次朴茨茅斯Bootstrap会议回覆:mailings@portsmouthbootstrap.org

我不知道为什么还会显示“答复”。我曾尝试添加\ n和\ r以及许多其他内容,但似乎无法阻止这种情况的发生。

我知道那里有更好的邮件系统,但是特别感谢您能给予的任何帮助。

        $mail_subject="Next Portsmouth Bootstrap meeting\r\n ";
        require("connectdb.php");

        $sql = mysqli_query($con, "SELECT email,name  FROM maillist WHERE subscribed='1'");
        if($sql === FALSE) { echo "err: ".mysqli_error($con); }

        $encoding = "utf-8";
        $subject_preferences = array(
        "input-charset" => $encoding,
        "output-charset" => $encoding,
        "line-length" => 76,
        "line-break-chars" => "\r\n"
);          

        while($row = mysqli_fetch_array($sql)) {
            $email = $row['email'];
            $name = $row['name'];
            echo "name=".$name." email=".$email."<br/>";
            $from_name="Portsmouth Bootstrap";
            $from_mail="mailings@portsmouthbootstrap.org";  
            $boundary = uniqid('np');   

            $headers = "MIME-Version: 1.0\r\n";
            $headers .= "From: ".$from_name." <".$from_mail."> \r\n";
            $headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
            $headers .= "Content-Transfer-Encoding: 8bit \r\n";
            $headers .= "Date: ".date("r (T)")." \r\n";
            $headers .= iconv_mime_encode("Subject", $mail_subject, $subject_preferences);
            $headers .= "Reply-To: mailings@portsmouthbootstrap.org\r\n";
            $headers .= "Return-Path: mailings@portsmouthbootstrap.org\r\n";
            $headers .= "X-Mailer: PHP/" . phpversion();

            $message = "This is a MIME encoded message.";
            $message .= "\r\n\r\n--" . $boundary . "\r\n";
            $message .= "Content-type: text/plain;charset=utf-8\r\n\r\n";
            //Plain text body
            $message .= $allmessageplain;
            $message .= "\r\n\r\n--" . $boundary . "\r\n";
            $message .= "Content-type: text/html;charset=utf-8\r\n\r\n";
            $unsub = "<p>To unsubscribe from this mailing list please click <a href='https://portsmouthbootstrap.org/unsub.php?email=".$email."'>here</a></p>";
            //Html body
            $message .= $allmessage.$unsub;
            $message .= "\r\n\r\n--" . $boundary . "--";

            mail($email, $mail_subject, $message, $headers);
        }

2 个答案:

答案 0 :(得分:2)

您必须在函数调用后附加换行符。

$headers .= iconv_mime_encode("Subject", $mail_subject, $subject_preferences) . "\r\n";

没有换行符,您将它们全部塞在一行中,但是两行需要分开。

答案 1 :(得分:0)

您要执行的操作是将标头作为数组传递。它为您省去了处理所有这些换行符的麻烦,这确实是您的原始问题。

$headers = [
    "MIME-Version"              => "1.0",
    "From"                      => "$from_name <$from_mail>",
    "Content-Type"              => "multipart/alternative;boundary=$boundary",
    "Content-Transfer-Encoding" => "8bit",
    "Date"                      => date("r (T)"),
    "Subject"                   => str_replace("Subject: ", "", iconv_mime_encode("Subject", $mail_subject, $subject_preferences)),
    "Reply-To"                  => "mailings@portsmouthbootstrap.org",
    "Return-Path"               => "mailings@portsmouthbootstrap.org",
    "X-Mailer"                  => "PHP/" . phpversion()
];

来自the documentation

  

additional_headers (可选)

     

要在电子邮件标题末尾插入的字符串或数组。

     

...

     

如果传递数组,则其键为标头名称,其值为相应的标头值。