我正在使用 php 的邮件功能发送电子邮件。电子邮件客户端中的某些地址(例如 aol、hotmail.com 和 msn)收不到它。Gmail 工作正常!我觉得很奇怪,因为它可以通过 Gmail,但不能通过其他人:
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers = "From: $from";
$headers .= "\r\nMIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
然后我使用以下方式发送电子邮件:
$ok = @mail($to, $subject, $message, $headers);
出于诊断目的,$header
字符串包含:
From: xxx@example.com
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="==Multipart_Boundary_xd31b2fcd6941ba77b38f866330c24944x"
并且$message
字符串包含:
This is a multi-part message in MIME format.
--==Multipart_Boundary_x0dde39863d56158409aa962fc1dd9a3bx
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
The email message appears here
--==Multipart_Boundary_x0dde39863d56158409aa962fc1dd9a3bx
Content-Type: {"application/octet-stream"};
name="afile.pdf"
Content-Disposition: attachment;
filename="afile.pdf"
Content-Transfer-Encoding: base64
The attachment's contents here
--==Multipart_Boundary_x0dde39863d56158409aa962fc1dd9a3bx