search
Homephp教程php手册PHP mailer邮件发送

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 "发送成功!";
}
?>
Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment