我想在電子郵件中同時發送html和純文本。我發現this pretty straightforward tutorial,但它使用mail()函數發送電子郵件。 如何將此代碼轉換爲PHP Mailer類發送電子郵件?用PHP同時發送html和純文本郵件Mailer
//specify the email address you are sending to, and the email subject
$email = '[email protected]';
$subject = 'Email Subject';
//create a boundary for the email. This
$boundary = uniqid('np');
//headers - specify your from email address and name here
//and specify the boundary for the email
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: Your Name \r\n";
$headers .= "To: ".$email."\r\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
//here is the content body
$message = "This is a MIME encoded message.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/plain;charset=utf-8\r\n\r\n";
//Plain text body
$message .= "Hello,\nThis is a text email, the text/plain version.
\n\nRegards,\nYour Name";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/html;charset=utf-8\r\n\r\n";
//Html body
$message .= "
Hello,
This is a text email, the html version.
Regards,
Your Name";
$message .= "\r\n\r\n--" . $boundary . "--";
//invoke the PHP mail function
mail('', $subject, $message, $headers);
精彩!我GOOGLE了這一點,但無法找到任何關於PHP Mailers AltBody屬性。像魅力一樣工作,我的電子郵件剛剛在http://www.mail-tester.com上收到了9.9而不是8.3! – erdomester
任何我需要照顧的東西,即純文本身體看起來應該如何?我的新行總是被刪除......'$ message ['plaintext'] = $ PHPMailer-> html2text($ message ['html']);' – user2966991
嘗試'$ PHPMailer-> html2text(nl2br($ message ['html' ]))' –