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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment