【发布时间】:2020-09-23 20:38:42
【问题描述】:
<?php
if(isset($_POST['sendmail'])) {
require 'PHPMailerAutoload.php';
require 'credential.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 4; // 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 = EMAIL; // SMTP username
$mail->Password = PASS; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom(EMAIL, 'litdeveloper');
$mail->addAddress($_POST['email']); // Add a recipient
$mail->addReplyTo(EMAIL);
// print_r($_FILES['file']); exit;
for ($i=0; $i < count($_FILES['file']['tmp_name']) ; $i++) {
$mail->addAttachment($_FILES['file']['tmp_name'][$i], $_FILES['file']['name'][$i]); // Optional name
}
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $_POST['subject'];
$mail->Body = '<div style="border:2px solid red;">This is the HTML message body <b>in bold!</b></div>'.$_POST['message'];
$mail->AltBody = $_POST['message'];
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}
?>
如何解决这个错误,我在评论此 $mail->isSMTP() 后也尝试过,但它不起作用。 它在 XAMP 上正常工作 电子邮件 ID 和密码是正确的我应该怎么做请帮助我
【问题讨论】:
-
你得到什么错误信息?
-
SMTP 连接()失败。 github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 无法发送邮件。邮件程序错误:SMTP 连接()失败。 github.com/PHPMailer/PHPMailer/wiki/Troubleshooting我在这里托管(litdeveloper.ml/donemail)请访问这里查看错误
-
您的服务器似乎不支持 SMTP。您应该检查这些配置设置。
-
显然gmail中有一些配置设置需要整理,请参阅先决条件部分pepipost.com/tutorials/…
-
在你的 localhost 环境中你也使用过 gmail 吗?
标签: php amazon-ec2 phpmailer ubuntu-18.04