PHP 使用PHPmailer发送邮件+附件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 使用PHPmailer发送邮件+附件相关的知识,希望对你有一定的参考价值。
require_once PATH . '/include/phpmailer/class.phpmailer.php';
$html_body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- Facebook sharing information tags -->
<meta property="og:title" content="EMAIL_SUBJECT" />
<title>EMAIL_SUBJECT</title>
</head>
<body>MAIL_TEXT</body>
</html>';
$text_body = 'MAIL_TEXT';
$mailer = new PHPMailer();
$mailer->From = 'FROM_EMAIL';
$mailer->FromName = 'FROM_NAME';
$mailer->Subject = 'SUBJECT';
$mailer->ContentType = 'text/html';
$mailer->CharSet = 'utf-8';
$mailer->Priority = 2;
$mailer->Body = $html_body;
$mailer->AltBody = $text_body;
$mailer->IsHTML(true);
$mailer->AddAddress(TO_EMAIL);
$mailer->AddReplyTo('REPLY_TO_EMAIL');
$mailer->AddAttachment('FILE_PATH', 'FILE_NAME');
if ($mailer->Send()) {
echo 'Mail sent';
} else {
echo 'Mail error';
}
以上是关于PHP 使用PHPmailer发送邮件+附件的主要内容,如果未能解决你的问题,请参考以下文章
PHPMailer-master不发送邮件[重复]
ThinkPHP5 封装邮件发送服务(可发附件)
phpmailer:发送带附件的电子邮件并设置文件名
PHP通过SMTP实现发送邮件_包括附件
ThinkPHP5 封装邮件发送服务(可发附件)
PHP下利用PHPMailer