PHP邮件程序错误:无法发送邮件。邮件程序错误:无效地址:(addAnAddress to):您的电子邮件
嗨,伙计们,我写得很正确,但是如果在网站上使用xampp或上传不起作用,那么我必须在gmail上激活允许问题应用程序,我不知道解决方案,请帮助我,我需要这个,以便有一个客户的联系表,通过邮件向我发送数据PHP邮件程序错误:无法发送邮件。邮件程序错误:无效地址:(addAnAddress to):您的电子邮件,php,phpmailer,Php,Phpmailer,嗨,伙计们,我写得很正确,但是如果在网站上使用xampp或上传不起作用,那么我必须在gmail上激活允许问题应用程序,我不知道解决方案,请帮助我,我需要这个,以便有一个客户的联系表,通过邮件向我发送数据 <?php use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; //Load composer's autoloader require 'vendor/autoloa
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
if(isset($_POST['send'])){
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
//Server settings
//$mail->SMTPDebug = 2; // Enable verbose debug output
$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 = 'i write my email but not work'; // SMTP username
$mail->Password = "i write my password but not work"; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom($email, $name);
$mail->addAddress('Your Email', 'Your Name'); // Add a recipient
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message . "<br> Sent from: Form";
$mail->send();
echo 'Message has been sent';
}
} catch (Exception $e) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
?>
<form action="" method="post">
<label>Name:</label><br><input type="text" name="name" placeholder="Your Name" required autocomplete="off" autofocus><br><br>
<label>Email:</label><br><input type="email" name="email" placeholder="Your Email" required autocomplete="off"><br><br>
<label>Subject:</label><br><input type="text" name="subject" placeholder="Your Subject" required autocomplete="off"><br><br>
<label>Message:</label><br><textarea name="message" placeholder="Your Message" required></textarea><br><br>
<input type="submit" name="send">
</form>
您需要更改此行以获得有效的电子邮件地址:
$mail->addAddress('Your Email', 'Your Name');
“您的电子邮件”应替换为“电子邮件”user@example.com'或任何其他电子邮件。您可以查看此视频,它将解决您的问题 您只需要编辑php.ini
和sendmail.ini邮件无法发送。邮件错误:SMTP错误:无法连接到SMTP主机。这就是问题所在,然后,您必须确保用户名和密码正确,端口正确,gmail设置正确如果取消注释
SMTPDebug
行,您将看到服务器在说什么,这可能会告诉你出了什么问题。还请阅读错误消息链接到的故障排除指南。我在问题中写入错误是的,但如果启用调试输出,您将看到更多信息,而不仅仅是最终状态。是的,我启用了此功能,现在我将错误正确地放在问题中,因此现在您可以看到在尝试启动TLS后失败的原因;故障排除指南中详细介绍了该问题。您很可能拥有过时的CA证书。
$mail->addAddress('Your Email', 'Your Name');