如何在PHP中使用PHPMailer发送邮件
1个回答
展开全部
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
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 = "<h1>phpmail演示</h1>这是php点点通(<font color=red>www.phpddt.com</font>)对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();
}
?>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
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 = "<h1>phpmail演示</h1>这是php点点通(<font color=red>www.phpddt.com</font>)对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();
}
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询