中3php,PHPMailer在thinkPHP3.2.3中的使用

本文档展示了如何使用PHPMailer库通过SMTP协议发送邮件。关键步骤包括下载PHPMailer库,配置SMTP服务器信息(如QQ邮箱),设置SMTPDebug、SMTPAuth、SMTPSecure等参数,并进行错误处理。在测试过程中,提到了QQ邮箱的SSL加密问题以及独立密码的使用。测试函数演示了如何创建并发送一封包含HTML内容的邮件。
摘要由CSDN通过智能技术生成

GitHub地址: https://github.com/PHPMailer/PHPMailer

解压下载文件 将 class.phpmailer.php class.pop3.php class.smtp.php 三个文件放入 ThinkPHP/Library/Vendor/PHPMailer 文件中

下面的测试函数仅使用了 SMTP协议。

注意的问题

1. 使用QQ邮箱测试的时候,需要注意QQ邮箱开启SMTP时设置的独立密码,而且QQ邮箱使用ssl加密时,发送邮件失败;

2. 当不使用加密时,$mail->SMTPSecure =''; 最好设置为空,因为本身是有默认值的

~~~

function sendEmailTest(){

vendor('PHPMailer.class#phpmailer'); // 从PHPMailer目录导class.phpmailer.php类文件

vendor('PHPMailer.class#smtp'); // 从PHPMailer目录导class.phpmailer.php类文件

$mail = new PHPMailer;

$mail->SMTPDebug = 0; // Enable verbose debug output 0表示关闭调试,1为打开调试

$mail->isSMTP(); // Set mailer to use SMTP

$mail->Host = 'smtp.qq.com'; // Specify main and backup SMTP servers

$mail->SMTPAuth = true; // Enable SMTP authentication

$mail->Username = '18559259538@qq.com'; // SMTP username

$mail->Password = '654312ab'; // SMTP password

$mail->SMTPSecure = ''; // Enable TLS encryption, `ssl` also accepted

$mail->Port = 25; // TCP port to connect to

$mail->CharSet ="UTF-8";//设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码

$mail->From = '18559259538@qq.com';

$mail->FromName = 'leviio';

$mail->addAddress('18559259538@qq.com', 'TESTNAME'); // Add a recipient

//$mail->addAddress('ellen@example.com'); // Name is optional

$mail->addReplyTo('leviio@qq.com', 'Informationeee'); // 回复设置 回复的邮件地址,回复的名字

//$mail->addCC('cc@example.com');

//$mail->addBCC('bcc@example.com');

//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments

//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name

$mail->isHTML(true); // Set email format to HTML

$mail->Subject = 'Here is the subject 测试头555';

$mail->Body = 'This is the HTML message body in bold!';

$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {

echo 'Message could not be sent.';

echo 'Mailer Error: ' . $mail->ErrorInfo;

} else {

echo 'Message has been sent';

}

}

~~~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值