以下是我用来发送带附件的电子邮件的代码。如果我发送电子邮件到hotmail或Outlook的帐户,代码工作正常,但当我发送电子邮件到Gmail的帐户时,代码不起作用。我收到了关于Gmail的电子邮件,但是电子邮件上写着垃圾,如下所示。请告诉我如何为gmail解决此问题。
This is a multi-part message in MIME format.
--==Multipart_Boundary_x9e353014396812b52f548f23d8c48987x
MIME-Version: 1.0
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
MY MESSAGE HTML CODE HERE
--==Multipart_Boundary_x9e353014396812b52f548f23d8c48987x
Content-Type: image/jpeg;
name="Newsroom image.jpg"
Content-Transfer-Encoding: base64
/9j/4AAQSkZJRgABAQEBLAEsAAD/7QB4UGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAFwcAmcAUDUz
NjE2Yzc0NjU2NDVmNWY5YzhiN2RjYWM5ZWIyNGFjODk4ZTQ3M2E5ZTY4N2Q1MGNmZmE5NDZlYzdj
NGM1NzkwZDVhN2UwY2VkNjQ3Y
代码 - 标题
// Now Generate a random string to be used as the boundary marker
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
// Now we'll build the message headers
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Next, we'll build the message body note that we insert two dashes in front of the MIME boundary when we use it
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
// Now we'll insert a boundary to indicate we're starting the attachment we have to specify the content type, file name, and disposition as an attachment, then add the file content and set another boundary to indicate that the end of the file has been reached
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$file_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" file=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";