Home > php教程 > php手册 > PHP mailer邮件发送

PHP mailer邮件发送

WBOY
Release: 2016-06-13 09:05:28
Original
1340 people have browsed it

PHP mailer邮件发送

首先下载类库 phpmailer因为加载的是smtp.163.php 故发件人的邮箱要用163邮箱 其它邮箱需要其它类库引入,我的附件.xls是你要添加的附件,可以是任意类型。

echo "

";
require_once('class.phpmailer.php');


$mail = new PHPMailer(); //实例化
$mail->IsSMTP(); // 启用SMTP
$mail->Host = "smtp.163.com"; //SMTP服务器 以163邮箱为例子
$mail->Port = 25; //邮件发送端口
$mail->SMTPAuth = true; //启用SMTP认证


$mail->CharSet = "UTF-8"; //字符集
$mail->Encoding = "base64"; //编码方式


$mail->Username = "yourmail@163.com"; //你的邮箱 163的
$mail->Password = "password"; //你的密码
$mail->Subject = "你好"; //邮件标题 任意


$mail->From = "youradmin@163.com"; //发件人地址(也就是你的邮箱)
$mail->FromName = "name"; //发件人姓名 任意


$address = "$_POST['email']";//收件人email 我是post传过来的 这个是收件人邮箱
$mail->AddAddress($address, "亲");//添加收件人(地址,昵称)


$mail->AddAttachment('xx.xls','我的附件.xls'); // 添加附件,并指定名称
$mail->IsHTML(true); //支持html格式内容
$mail->AddEmbeddedImage("logo.jpg", "my-attach", "logo.jpg"); //设置邮件中的图片
$mail->Body = '你好, 朋友!
这是一封来自helloweba.com的邮件!
'; //邮件主体内容


//发送
if(!$mail->Send()) {
echo "发送失败: " . $mail->ErrorInfo;
} else {
echo "发送成功!";
}
?>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template