Home  >  Article  >  Backend Development  >  Example of sending emails using PHPMailer mail class (163 mailbox)

Example of sending emails using PHPMailer mail class (163 mailbox)

WBOY
WBOYOriginal
2016-07-25 08:59:521293browse
Let me introduce you to an example of sending emails with PHPMailer, using smtp.163.com as the smtp when sending. Friends in need can refer to it.

1. Download the PHPMailer file package, PHPMailer email sending class V5.1 download address. 2. Confirm that the server supports sockets and check whether sockets are supported. Note: socket is a PHP extension, and a configuration option for ./configure --enable-sockets must be given when compiling.

3. Unzip the file to your web server directory and call the class. Description: First include class.phpmailer.php, then create the object, set parameters, and call member functions.

The code is as follows:

IsSMTP(); // send via SMTP
$mail->Host = "200.162.244.66"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "yourmail"; // SMTP username 注意:普通邮件认证不需要加 @域名
$mail->Password = "mailPassword"; // SMTP password

$mail->From = "yourmail@jbxue.com"; // 发件人邮箱
$mail->FromName = "jbxue.com管理员"; // 发件人

$mail->CharSet = "GB2312"; // 这里指定字符集!
$mail->Encoding = "base64";

$mail->AddAddress($sendto_email,"username"); // 收件人邮箱和姓名
$mail->AddReplyTo("yourmail@jbxue.com","jbxue.com");

//$mail->WordWrap = 50; // set word wrap
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
$mail->IsHTML(true); // send as HTML
// 邮件主题
$mail->Subject = $subject;
// 邮件内容
$mail->Body = '



欢迎来到http://bbs.it-home.org

感谢您注册为本站会员!

'; $mail->AltBody ="text/html"; if(!$mail->Send()) { echo "邮件发送有误

"; echo "邮件错误信息: " . $mail->ErrorInfo; exit; } else { echo "$user_name 邮件发送成功!
"; } } // 参数说明(发送到, 邮件主题, 邮件内容, 附加信息, 用户名) smtp_mail('yourmail@jbxue.com', '欢迎来到jbxue.com!', 'NULL', 'jbxue.com', 'username'); ?>

Note: 1. Mail character set setting, $mail->CharSet = "GB2312"; // Specify the character set! I only specify GB2312 here because this way Outlook can display the email subject normally. I tried setting it to utf-8, but it showed garbled characters in Outlook.

2. Send emails in html format, remember to specify 3. When sending mass emails, remember to modify the included file function, such as: require("phpmailer/class.phpmailer.php"); Change to require_once("phpmailer/class.phpmailer.php"); Otherwise, you will be prompted to redefine the class.



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