PHP mail()将消息源显示为正文文本

PHP mail()将消息源显示为正文文本,php,email,Php,Email,我一直在与此电子邮件设置进行斗争。下面的代码在我的服务器上工作,但在客户机的服务器上,它将消息源(从reply to)显示为消息正文。它所在的服务器是plesk服务器。有人能帮我吗?我确信这是标题的问题,因为如果我取出回复标题,它会正确显示在hotmail和googlemail中,但不会显示在常规电子邮件帐户中。提前感谢你的帮助 更新 它在我使用thunderbird的电子邮件帐户中显示得很好,但我的老板使用macmail,除了几行源代码外,仍然一无所获。我们都使用同一台服务器发送电子邮件 第二

我一直在与此电子邮件设置进行斗争。下面的代码在我的服务器上工作,但在客户机的服务器上,它将消息源(从reply to)显示为消息正文。它所在的服务器是plesk服务器。有人能帮我吗?我确信这是标题的问题,因为如果我取出回复标题,它会正确显示在hotmail和googlemail中,但不会显示在常规电子邮件帐户中。提前感谢你的帮助

更新

它在我使用thunderbird的电子邮件帐户中显示得很好,但我的老板使用macmail,除了几行源代码外,仍然一无所获。我们都使用同一台服务器发送电子邮件

第二次更新

它现在可以在除macmail之外的所有我可以访问的地方工作。文件根本无法打开,说它已损坏或无法识别。有什么想法吗

//define the receiver of the email
$to = 'bionic.comms@hotmail.com';
//define the subject of the email
$subject = 'Email with Attachment';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$mime_boundary = "<<<--==+X[".md5(time())."]";

$path = $_SERVER['DOCUMENT_ROOT'].'/two/php/';
$fileContent =  chunk_split(base64_encode(file_get_contents($path.'CTF_brochure.pdf')));


$headers .= "From: info@poundsandpennies.org.uk <info@poundsandpennies.org.uk>"."\r\n";

$headers .= "MIME-Version: 1.0\n" .
            "Content-Type: multipart/mixed;\n" .
            " boundary=\"{$mime_boundary}\"";   

$message = "This is a multi-part message in MIME format.\r\n";

$message .= "\r\n";
$message .= "--".$mime_boundary."\r\n";

$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$message .= "Content-Transfer-Encoding: base64\r\n";
$message .= "\r\n";
$message .= "Email content and what not: \r\n";
$message .= "This is the file you asked for! \r\n";
$message .= "--".$mime_boundary."" . "\r\n";

$message .= "Content-Type: application/octet-stream;\r\n";
$message .= " name=\"CTF-brochure.pdf\"" . "\r\n";
$message .= "Content-Transfer-Encoding: base64 \r\n";
$message .= "Content-Disposition: attachment;\r\n";
$message .= " filename=\"CTF_brochure.pdf\"\r\n";
$message .= "\r\n";
$message .= $fileContent;
$message .= "\r\n";
$message .= "--".$mime_boundary."\r\n";

//send the email
$mail_sent = mail($to, $subject, $message, $headers);
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
//定义电子邮件的收件人
$to='仿生。comms@hotmail.com';
//定义电子邮件的主题
$subject='带附件的电子邮件';
//创建一个边界字符串。它必须是独一无二的
//所以我们使用MD5算法来生成一个随机散列
$random_hash=md5(日期('r',时间());
//定义我们想要传递的标题。请注意,它们用分隔符分隔\r\n

$mime_boundary=“他们可能有一个邮件服务器,该服务器希望以“\n”作为行的结尾。太可怕了,但它确实发生了

您还缺少最终MIME边界中的“-”:

$message .= "--".$mime_boundary."--\r\n";

//send the email
$mail_sent = mail($to, $subject, $message, $headers);

关于使用图书馆而不是写你自己的…

谢谢你,我真的很感激。我现在什么也没有显示。我尝试了几个图书馆,但都没有成功地让他们来做这件事,从我自己的学习来看,我能自己完成总是更好的。你能把这条消息贴到我的网站上吗生成的rce(截取大部分PDF)内容类型:text/plain;charset=“iso-8859-1”内容传输编码:7比特电子邮件内容和其他内容:这是您要求的文件! 内容类型:应用程序/octet流;name=“CTF宣传册.pdf”内容传输编码:base64内容处置:附件;filename=“CTF_宣传册.pdf“----剩下的只是散列字符串而已。我刚刚再次尝试了您的修复,现在它可以工作了。大部分时间!我收到一封包含正确信息和附件的电子邮件,但文件没有打开!再次感谢