PHP:发送纯文本+HTML电子邮件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP:发送纯文本+HTML电子邮件相关的知识,希望对你有一定的参考价值。
<?php //define the receiver of the email //define the subject of the email // Generate a random boundary string // Using the heredoc syntax to declare the headers $headers = <<<HEADERS From: Test <[email protected]> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="PHP-alt$mime_boundary" HEADERS; // Use our boundary string to create plain text and HTML versions $message = <<<MESSAGE --PHP-alt$mime_boundary Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit This Is a Plain Text Email This message has no HTML. http://w3schools.com --PHP-alt$mime_boundary Content-type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 7bit <html> <body> <h1>This Is an HTML Email</h1> <p> This message is composed in <a href="http://w3schools.com">HTML</a>. </p> </body> </html> --PHP-alt$mime_boundary-- MESSAGE; // Send the message { // If the mail function fails, return an error message echo "Something went wrong!"; } else { // Return a success message if nothing went wrong echo "Message sent successfully. Check your email!"; } ?>
以上是关于PHP:发送纯文本+HTML电子邮件的主要内容,如果未能解决你的问题,请参考以下文章
如何通过 Celery 发送 HTML 电子邮件?它不断发送文本/纯文本