PHPMailer使用教程(PHPMailer发送邮件实例分析)_php实例
May 17, 2016 am 09:07 AMphp虽然提供了mail()函数,但并不好用,而PHPMailer是一个不错的邮件发送工具,使用起来也是非常简单!
使用PHPMailer发送邮件:
header("content-type:text/html;charset=utf-8");
ini_set("magic_quotes_runtime",0);
require 'class.phpmailer.php';
try {
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->CharSet='UTF-8'; //设置邮件的字符编码,这很重要,不然中文乱码
$mail->SMTPAuth = true; //开启认证
$mail->Port = 25;
$mail->Host = "smtp.163.com";
$mail->Username = "phpddt1990@163.com";
$mail->Password = "这是密码";
//$mail->IsSendmail(); //如果没有sendmail组件就注释掉,否则出现“Could not execute: /var/qmail/bin/sendmail ”的错误提示
$mail->AddReplyTo("phpddt1990@163.com","mckee");//回复地址
$mail->From = "phpddt1990@163.com";
$mail->FromName = "www.phpddt.com";
$to = "987044391@qq.com";
$mail->AddAddress($to);
$mail->Subject = "phpmailer测试标题";
$mail->Body = "
phpmail演示
这是php点点通(www.phpddt.com)对phpmailer的测试内容";$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; //当邮件不支持html时备用显示,可以省略
$mail->WordWrap = 80; // 设置每行字符串的长度
//$mail->AddAttachment("f:/test.png"); //可以添加附件
$mail->IsHTML(true);
$mail->Send();
echo '邮件已发送';
} catch (phpmailerException $e) {
echo "邮件发送失败:".$e->errorMessage();
}
?>
打开我的qq邮件可以看到:

测试非常顺利:
从上图可以看出,PHPMailer是支持html格式发送,而且支持发送图片,附件!经过测试,对各种SMTP服务器兼容很好!
添加附件如果报错:
那是因为(set_magic_quotes_runtime())已经关闭。并且在PHP6中已经完全移除此特性。
你可以注释或者删除掉出错的行,或者是在set_magic_quotes_runtime()前面加@符号
或者是配置;error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED
PHPMailer及测试文件下载:phpmailer.rar

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP development practice: Use PHPMailer to send emails to users in the MySQL database

PHP methods and steps for sending emails to multiple people using PHPMailer

Python connects to Alibaba Cloud interface to implement email sending function

How to send emails using PHP email() function

The complete process of sending emails using PHP mail function

Comprehensive Guide to Sending Mail via SMTP with PHP
