Table of Contents
phpmail演示
Home Backend Development PHP Tutorial PHPMailer使用教程(PHPMailer发送邮件实例分析)_php实例

PHPMailer使用教程(PHPMailer发送邮件实例分析)_php实例

May 17, 2016 am 09:07 AM
send email

php虽然提供了mail()函数,但并不好用,而PHPMailer是一个不错的邮件发送工具,使用起来也是非常简单!

使用PHPMailer发送邮件

复制代码 代码如下:

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 = "

phpmail演示

这是php点点通(www.phpddt.com)对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();
}
?>

打开我的qq邮件可以看到:
使用PHPMailer发送邮件
测试非常顺利:

从上图可以看出,PHPMailer是支持html格式发送,而且支持发送图片,附件!经过测试,对各种SMTP服务器兼容很好!

添加附件如果报错:

那是因为(set_magic_quotes_runtime())已经关闭。并且在PHP6中已经完全移除此特性。

你可以注释或者删除掉出错的行,或者是在set_magic_quotes_runtime()前面加@符号
或者是配置;error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED

PHPMailer及测试文件下载:phpmailer.rar

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP development practice: Use PHPMailer to send emails to users in the MySQL database PHP development practice: Use PHPMailer to send emails to users in the MySQL database Aug 05, 2023 pm 06:21 PM

PHP development practice: Use PHPMailer to send emails to users in the MySQL database

PHP methods and steps for sending emails to multiple people using PHPMailer PHP methods and steps for sending emails to multiple people using PHPMailer May 22, 2023 pm 06:10 PM

PHP methods and steps for sending emails to multiple people using PHPMailer

How to send email using Flask-Mail How to send email using Flask-Mail Aug 02, 2023 am 10:17 AM

How to send email using Flask-Mail

Python connects to Alibaba Cloud interface to implement email sending function Python connects to Alibaba Cloud interface to implement email sending function Jul 05, 2023 pm 04:33 PM

Python connects to Alibaba Cloud interface to implement email sending function

How to send mail using PHP queue? How to send mail using PHP queue? Sep 13, 2023 am 08:00 AM

How to send mail using PHP queue?

How to send emails using PHP email() function How to send emails using PHP email() function May 22, 2023 pm 03:10 PM

How to send emails using PHP email() function

The complete process of sending emails using PHP mail function The complete process of sending emails using PHP mail function May 22, 2023 am 08:00 AM

The complete process of sending emails using PHP mail function

Comprehensive Guide to Sending Mail via SMTP with PHP Comprehensive Guide to Sending Mail via SMTP with PHP May 27, 2023 am 10:10 AM

Comprehensive Guide to Sending Mail via SMTP with PHP

See all articles