"Reply-To" 在电子邮件的主题行上(使用 php 邮件)
"Reply-To" on subject line of email (using php mail)
我已经使用 php 邮件为邮寄列表设置了一个简单的电子邮件,并且使用我找到的教程,我使用边界以普通和 html 发送它。
一切正常,除了主题行显示为
下一次朴茨茅斯 Bootstrap 会议 Reply-To:mailings@portsmouthbootstrap.org
我不知道为什么 "Reply-To" 也显示了。我已经尝试添加 \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);
}
您必须在函数调用后附加换行符。
$headers .= iconv_mime_encode("Subject", $mail_subject, $subject_preferences) . "\r\n";
没有换行符,您将所有内容都塞在一行中,但两行需要分开。
您要做的是将 headers 作为数组传递。它省去了处理所有这些换行符的麻烦,这确实是你原来的问题。
$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()
];
additional_headers (optional)
String or array to be inserted at the end of the email header.
...
If an array is passed, its keys are the header names and its values are the respective header values.
我已经使用 php 邮件为邮寄列表设置了一个简单的电子邮件,并且使用我找到的教程,我使用边界以普通和 html 发送它。
一切正常,除了主题行显示为
下一次朴茨茅斯 Bootstrap 会议 Reply-To:mailings@portsmouthbootstrap.org
我不知道为什么 "Reply-To" 也显示了。我已经尝试添加 \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);
}
您必须在函数调用后附加换行符。
$headers .= iconv_mime_encode("Subject", $mail_subject, $subject_preferences) . "\r\n";
没有换行符,您将所有内容都塞在一行中,但两行需要分开。
您要做的是将 headers 作为数组传递。它省去了处理所有这些换行符的麻烦,这确实是你原来的问题。
$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()
];
additional_headers (optional)
String or array to be inserted at the end of the email header.
...
If an array is passed, its keys are the header names and its values are the respective header values.