PHP邮件功能不能在aws上工作


php mailer function not working on aws

我使用PHP mailer函数发送邮件。这段代码可以在XAMPP和000webhost.com上工作,但不能在aws上工作。

<?php
require("'PHPMailer'PHPMailer'class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
//$mail->SMTPDebug = true;
$mail->SMTPSecure = "tls";
$mail->Host  = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port  = 587;    
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "****@gmail.com"; // Enter your SMTP username
$mail->Password =  "************"; // SMTP password
$webmaster_email = $_POST['email']; //Add reply-to email address
$email= "***@gmail.com"; // Add recipients email address
$name= "Recipient's name"; // Add Your Recipient’s name
$mail->From = $webmaster_email;
$mail->FromName = $_POST['name'];
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,$_POST['name']);
$mail->WordWrap = 500; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "website inquiry - Support";
$mail->Body = nl2br($_POST['message']);
$mail->AltBody = nl2br($_POST['message']);     //Plain Text Body
if($mail->Send())
  echo 1;
else
  echo 0;
?>
请告诉我哪里做错了。当我在aws上执行这段代码时,它回显0

提前感谢!

通过在构造函数中添加"true"来尝试抛出错误:

try {
    new PHPMailer(true);
    ...your code here...
}
catch (phpmailerException $e) {
    echo $e->errorMessage();
}

也许还有更多关于错误的信息