我已完成所有更改,关闭了两步验证,还打开了不安全的应用程序。但是,当我看到PHP邮件发送器发送电子邮件时,将向我显示此错误。相同的代码在localhost中工作正常,但是当我将其上载到服务器时,它曾调用此错误。我正在使用AWS服务器SMTP错误:密码命令失败:我该如何绕过它以使用我的网站联系表
<?php
get_header(); ?>
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
if (isset($_POST['submit'])) {
require 'wp-content/themes/oceanwp/PHPMailer-master/src/Exception.php';
require 'wp-content/themes/oceanwp/PHPMailer-master/src/PHPMailer.php';
require 'wp-content/themes/oceanwp/PHPMailer-master/src/SMTP.php';
// require 'vendor/autoload.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 1; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '*****@gmail.com'; // SMTP username
$mail->Password = '******'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom($_POST['email_of_user'], $_POST['name_of_user']);
$mail->addAddress('&&&&@gmail.com', 'Joe User'); // Add a recipient
$mail->addAddress('&&&&@gmail.com', 'VASTRA'); // Name is optional
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $_POST['subject_of_user'] ;
$mail->Body = '<p style="text-align:center">'.$_POST['message_of_user'].'</p>';
$mail->AltBody = 'I have a qquery';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
} //end if loop
?>
您可以简单地使用此示例:
require_once "vendor/autoload.php";
//PHPMailer Object
$mail = new PHPMailer;
//From email address and name
$mail->From = "[email protected]";
$mail->FromName = "Full Name";
//To address and name
$mail->addAddress("[email protected]", "Recepient Name");
$mail->addAddress("[email protected]"); //Recipient name is optional
//Address to which recipient will reply
$mail->addReplyTo("[email protected]", "Reply");
//CC and BCC
$mail->addCC("[email protected]");
$mail->addBCC("[email protected]");
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
此示例使用简单域电子邮件,并在没有设置密码或任何smtp参数的情况下发送了该电子邮件