<?php
$mailto = $_POST['mail_to'];
$mailSub = $_POST['mail_sub'];
$mailMsg = $_POST['mail_msg'];
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail ->IsSmtp();
$mail ->SMTPDebug = 0;
$mail ->SMTPAuth = true;
$mail ->SMTPSecure = 'ssl';
$mail ->Host = "smtp.gmail.com";
$mail ->Port = 465; // or 587
$mail ->IsHTML(true);
$mail ->Username = "alxxxxxxxx@gmail.com";
$mail ->Password = "xxxxxxxxx";
$mail ->SetFrom("alxxxxxxx@gmail.com");
$mail ->Subject = $mailSub;
$mail ->Body = $mailMsg;
$mail ->AddAddress($mailto);
if(!$mail->Send())
{
echo "Mail Not Sent";
}
else
{
echo "Mail Sent";
}
这适用于XAMPP,但不适用于cpanel。当我尝试发送电子邮件时,它显示“ Mail Not Sent”消息。但是当我发表评论
$mail ->IsSmtp();
工作正常。据我所知,这是不好的,因为那时它没有使用SMTP协议。有什么解决办法吗?