Home  >  Article  >  Backend Development  >  Simple example of using phpMailer

Simple example of using phpMailer

WBOY
WBOYOriginal
2016-07-25 08:52:521181browse
This article introduces the simple usage of the phpmailer email class, a simple example of the phpmailer class, and serves as an introductory reference for the phpmailer class library. Friends who need it can take a look.

In PHP programming, you often need to send emails, such as email reminders for user registration, etc. You can use a good open source module: phpmailer. This module has comprehensive functions and supports SMTP verification.

How to use: 1. Download the phpmailer module: Official website http://www.phpdoc.org/

2. Unzip to a folder

3, include require_once("class.phpmailer.php");

in the php file

4. Use smtp to send emails (example of sending emails with phpmailer):

$mail = new PHPMailer();     //得到一个PHPMailer实例

$mail->CharSet = "gb2312";  //设置采用gb2312中文编码
$mail->IsSMTP();   //设置采用SMTP方式发送邮件
$mail->Host = "192.168.1.27";    //设置邮件服务器的地址
$mail->Port = 25;  //设置邮件服务器的端口,默认为25

$mail->From     = "mailFrom@tencent.com";  //设置发件人的邮箱地址
$mail->FromName = "samzhang";  //设置发件人的姓名
//$mail->SMTPAuth = true;  //设置SMTP是否需要密码验证,true表示需要

$mail->Username="samzhang";

$mail->Password = 'your password";
$mail->Subject = $subject;  //设置邮件的标题

$mail->AltBody = "text/html"; // optional, comment out and test

$mail->Body = "你的邮件的内容";                    

$mail->IsHTML(true);  //设置内容是否为html类型
//$mail->WordWrap = 50;   //设置每行的字符数
$mail->AddReplyTo("samzhang@tencent.com","samzhang");     //设置回复的收件人的地址
$mail->AddAddress("mailTo@tencent.com","toName");     //设置收件的地址
if(!$mail->Send()) {    //发送邮件
  echo 发送失败:';
 } 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