问题:使用HTML和附件发送的电子邮件不显示内容。附件没有问题。在我尝试将其作为HTML电子邮件发送之前,邮件和附件都很好。
代码:我使用以下代码发送带附件的电子邮件:
//Email to Customer or Tech
$file = "../PDF/phptopdf/".$_GET['pdf'];
$lgth = strlen($_GET['pdf']);
$intsta = strpos($_GET['pdf'],'/')+1;
$intend = $lgth - strpos($_GET['pdf'],'.');
$intendname = $lgth - strpos($_GET['pdf'],'_');
$filename = substr($_GET['pdf'],$intsta,-$intend);
$content = file_get_contents($file);
$content = chunk_split(base64_encode($content));
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (RFC)
$eol = "\r\n";
// main header (multipart mandatory)
$headers = "From: ".$_SESSION['userFName']." ".$_SESSION['userLName']." <".$_SESSION['email'].">" . $eol;
$headers .= "MIME-Version: 1.0" . $eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
$headers .= "Content-Transfer-Encoding: 8bit" . $eol;
// message
$body = "--" . $separator . $eol;
$body .= "Content-Type: text/html; charset=iso-8859-1" . $eol;
$body .= "Content-Transfer-Encoding: quoted-printable" . $eol;
if ($_POST['sendToTech'] == '1') {
$mailto = $_POST['techEmail'];
$subject = 'New Work Order for '.$compName;
$pos = strpos($_POST['techName'],' ');
$techFName = substr($_POST['techName'],0,$pos);
$message = "<html><body>";
$message .= "<table style='border:1px solid #000;font-size:18px;line-height:20px;'><tr><td style='text-align:center;padding:10px;'><img src='MY LOGO URL' /></tr></td>";
$message .= "<tr><td style='padding:10px;'>";
$message .= "Hello ".$techFName.", <br/><br/>";
$message .= "I have assigned work order #00-".$_GET['idQ']." for ".$compName." to you. <br/>";
$message .= "The work is scheduled for ".date('F jS, Y \a\t g:i A',strtotime($serviceDate))." at ".$address.". <br/>";
$message .= "Click on the attachment to view the work order or <a href='MYURL".$_GET['pdf']."'>Click Here</a>. <br/><br/>";
$message .= "Thank you, <br/>";
$message .= $_SESSION['userFName']."<br/><br/></tr></td></table></body></html>";
$body .= $message . $eol;
// attachment
$body .= "--" . $separator . $eol;
$body .= "Content-Type: application/pdf; name=\"" . $filename . "\"" . $eol;
$body .= "Content-Transfer-Encoding: base64" . $eol;
$body .= "Content-Disposition: attachment" . $eol;
$body .= $content . $eol;
$body .= "--" . $separator . "--";
//SEND Mail
if (mail($mailto, $subject, $body, $headers)) {
echo "<span class='message mg'>Work Order #00-".$idQ." has been emailed to ".$_POST['techName']." at ".$_POST['techEmail']."</span><br/>";
} else {
$msg[] = "Error: " . $mysqli->error;
echo "<span class='message alert'>An error occured while attempting to send Work Order #00-".$idQ." to ".$_POST['techEmail']."</span>";
}
}
当电子邮件到达时,它看起来像这样: Email in Gmail
但是,当我查看原始邮件时,我看到了未显示的内容: Original Message View
我尝试过的解决方案:
$body .= "Content-Type: text/html; charset=iso-8859-1" . $eol;
更改为text/plain
(只是为了看看是否可以做任何事情......)更改$headers .= "Content-Transfer-Encoding: 8bit" . $eol;
- 来自7bit
和quoted-printable
删除<html><body>
并关闭代码