我正在使用phpmailer。在我更改Gmail中的“lesssecureapps”选项后,它在localhost中运行正常。但是在吊装之后,它无法在网络服务器上运行。我的代码如下:
public function sendMail($userEmail, $uniqueKey)
{
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxxxx@gmail.com'; // SMTP username
$mail->Password = 'xxxxxxxx'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('contact@lookwoow.com', 'lookswoow');
//$mail->addReplyTo('arn617mv@gmail.com', 'sajeev');
$mail->addAddress("$userEmail"); // Add a recipient
//$mail->addCC("vishnu@f12technologies.com");
//$mail->addBCC('vishnu@f12technologies.com');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Email from LOOKSWOOW';
$mail->Body = $uniqueKey;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}