慕桂英6418607
2018-12-27 14:24
<?php
/**
*
* @authors yxq (you@example.org)
* @date 2018-12-14 16:15:05
* @version $Id$
*/
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$rootPath=dirname(__FILE__);
include($rootPath.'/PHPMailer-master\src\PHPMailer.php');
include($rootPath.'/PHPMailer-master\src\Exception.php');
include($rootPath.'/PHPMailer-master\src\OAuth.php');
include($rootPath.'/PHPMailer-master\src\POP3.php');
include($rootPath.'/PHPMailer-master\src\SMTP.php');
//Load Composer's autoloader
require $rootPath.'/vendor/autoload.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.aliyun.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'thetimetravel@aliyun.com'; // SMTP username
$mail->Password = '123456'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;
$mail->CharSet='UTF-8';
$mail->SMTPDebug = 4;
// TCP port to connect to
//Recipients
$mail->setFrom('thetimetravel@aliyun.com', 'Mailer2');
$mail->addAddress('766496095@qq.com', 'Joe User2'); // Add a recipient
// $mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('thetimetravel@aliyun.com', 'Information2');
// $mail->addCC('cc@example.com');
// $mail->addBCC('bcc@example.com');
//Attachments
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
// $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
还没有人回答问题,可以看看其他问题
php+mysql 模拟队列发送邮件
16223 学习 · 31 问题
相似问题