我正在尝试使用PHPMailer发送gmail电子邮件.我跟着这篇文章
为此,我设置了如下所示的函数:
function sendEmail($email, $name) {
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
//IsSMTP(); // send via SMTP I commented it cos it gives an error
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = 'email@gmail.com'; // Changed my email
$mail->Password = "password";// Changed my password
$mail->From = 'email@gmail.com';
$mail->FromName = 'FROM NAME';
$mail->AddAddress($email);
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Subject";
$mail->Body = "Body";
if (!$mail->Send()) {
return false;
} else {
return true;
} …Run Code Online (Sandbox Code Playgroud) 可能重复:
PHPMailer遇到问题
有很多类似的问题,但没有一个帮助我.
这是我的脚本,它在phpmailer exmaples中提供:
require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets …Run Code Online (Sandbox Code Playgroud)