[英]Unreadable email sent with PHPmailer
I use PHPMail to send an email with pdf attachment. 我使用PHPMail发送带有pdf附件的电子邮件。 In most cases (about 90% of the times) the email gets send properly, but in some cases and I don't know in which cases, the email will show like this:
在大多数情况下(大约90%的时间),电子邮件可以正确发送,但是在某些情况下,我不知道在哪种情况下,电子邮件将显示如下:
:
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="b1_a3f9faae87f56d6f3d5b7325ee3fadf5"
--b1_a3f9faae87f56d6f3d5b7325ee3fadf5
Content-Type: multipart/alternative;
boundary="b2_a3f9faae87f56d6f3d5b7325ee3fadf5"
--b2_a3f9faae87f56d6f3d5b7325ee3fadf5
Content-Type: text/plain; charset = "iso-8859-1"
Content-Transfer-Encoding: 8bit
Schakel HTML in om dit bericht goed te kunnen lezen
--b2_a3f9faae87f56d6f3d5b7325ee3fadf5
Content-Type: text/html; charset = "iso-8859-1"
Content-Transfer-Encoding: 8bit
<br><br>
<table cellpadding='0'>
<tr>
<td> </td>
<td width='130'><img src='http://www.emdr-lightbar.nl/images/psytec_mail.png' width='108' height='42' alt='Psytec'/></td>
<td><b>FACTUUR</b></td>
</tr>
<tr>
<td style='border-top: 0px;border-bottom: 0px;'> </td>
<td style='border-bottom: 1px solid #ededed !important;' colspan='2'></td>
</tr>
<tr>
<td width='20'> </td>
<td colspan='2'><font face='Arial, Helvetica, sans-serif' size='2'>
<br><br>
Geachte mevrouw,<br><br>
Uw betaling is in goede orde ontvangen. Dank u wel. Uw factuur vindt u in de bijlage van deze email.
<br><br>
Heeft u nog vragen? Neemt u dan contact op via de klantenservice</a>.
<br><br>
Uw ordernummer: 151<br><br>
Met vriendelijke groet,<br>
Fred Verschuur
<br><br><br>
</font>
</td>
<tr>
<td style='border-top: 0px;border-bottom: 0px;'> </td>
<td style='border-bottom: 1px solid #ededed !important;
color: #757575;' colspan='2'></td>
</tr>
</table>
<br><br><br><br><br><br>
--b2_a3f9faae87f56d6f3d5b7325ee3fadf5--
--b1_a3f9faae87f56d6f3d5b7325ee3fadf5
Content-Type: application/pdf; name="FA2015161.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="FA2015161.pdf"
JVBERi0xLjQKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNlcyAy
IDAgUgovQW5ub3RzIFs8PC9UeXBlIC9Bbm5vdCAvU3VidHlwZSAvTGluayAvUmVjdCBbMjkwLjcz
IDI0MS44OSA0MDQuMjUgMjMxLjg5XSAvQm9yZGVyIFswIDAgMF0gL0EgPDwvUyAvVVJJIC9VUkkg
KG1haWx0bzprbGFudGVuc2VydmljZUBwc3l0ZWMubmwpPj4+Pl0KL0dyb3VwIDw8L1R5cGUgL0dy
b3VwIC9TIC9UcmFuc3BhcmVuY3kgL0NTIC9EZXZpY2VSR0I+PgovQ29udGVudHMgNCAwIFI+Pgpl
I used this code: 我使用以下代码:
<?PHP
function mailTo($to, $subject, $fromname, $message, $headers, $attachment, $attname) {
global $mailer_user, $mailer_pass;
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$body = preg_replace('/\[\]/',"",$message);
$mail->IsSMTP();
$mail->Host = "smpt.server.nl";
$mail->SMTPAuth = true;
$mail->Host = "smpt.server.nl";
$mail->Port = 26;
$mail->Username = "username";
$mail->Password = "password";
$mail->IsHTML(true);
$mail->AltBody = "Schakel HTML in om dit bericht goed te kunnen lezen";
$mail->AddReplyTo('reply@domain.nl', 'Name');
$mail->SetFrom('klantenservice@domain.nl', 'Name');
$mail->FromName = $fromname;
$mail->AddBCC('bcc@domain.nl');
$mail->Subject = $subject;
$mail->Body = $body;
$mail->addCustomHeader($headers);
$address = $to;
$mail->AddAddress($address, $address);
if ($attachment) $mail->AddStringAttachment($attachment, $attname, $encoding = 'base64', $type = 'application/pdf');
if(!$mail->Send()) {
return false;
} else {
return true;
}
}
?>
How can I fix this? 我怎样才能解决这个问题?
Must be some kind of problem inside the mail headers. 邮件标题中一定有某种问题。
$mail->addCustomHeader($headers);
What's inside $headers
? $headers
里面有什么?
And what if you remove that line to test? 如果删除该行进行测试怎么办?
Update : 更新 :
Your headers are almost certainly broken somewhere. 您的标头几乎可以肯定在某个地方坏了。 For example, the shown email(body) starts with a single
:
on the whole line. 例如,显示的email(body)在整个行中以单个
:
开头。 So, somewhere before that there is a problem, probably caused by the contens of $headers
- or $headers
being empty or undefined as you say. 因此,在此之前的某个地方存在问题,可能是由于
$headers
-或$headers
为空或未定义(如您所说)。 And the remaining headers are pushed into the body of the mail, breaking all the MIME
formatting. 其余的标头被压入邮件的正文中,破坏了所有的
MIME
格式。
So I would start by removing $mail->addCustomHeader($headers);
因此,我将从删除
$mail->addCustomHeader($headers);
to test if the problem is within $headers
. 测试问题是否在
$headers
。
Use isHTML()
after body. isHTML()
后使用isHTML()
。 Its work for me in past. 过去对我有用。
$mail->Body = $body;
$mail->IsHTML(true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.