我一直在与这个电子邮件设置进行斗争。下面的代码在我的服务器上工作,但在客户机的服务器上,它将消息源(从答复到)显示为消息正文。它所在的服务器是PLESK服务器。有人能帮我吗?我确信邮件头有问题,因为如果我取出回复邮件头,它会正确显示在hotmail和googlemail中,但不是普通的电子邮件帐户。事先谢谢你的帮助。
更新
它在我使用雷鸟的电子邮件帐户中显示的很好,但是我的老板使用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";