【发布时间】:2018-01-04 19:23:18
【问题描述】:
邮件未使用 sendgrid 通过 SMTP 发送给用户。它显示 SMTP 错误
代码
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.sendgrid.net"; // SMTP server
$mail->SMTPSecure = "SSL";
$mail->SMTPAuth = true;
$mail->Username = "szdfsdf";
$mail->Password = "sdfsdfsdfsdf";
$mail->Port = "465";
$mail->From = "tests@gmail.com";
$mail->FromName = "Test";
$mail->AddAddress("test@services.in");
$message = "hi how r u in medapps?";
$message = trim($message);
$mail->Subject = "from test";
$mail->Body = trim($message);
if(!$mail->Send()){
echo "Mailer error: ".$mail->ErrorInfo;
}
else{
echo "Mail triggered to alert the status!";
}
结果
邮件程序错误:SMTP 错误:无法连接到 SMTP 主机。
【问题讨论】:
-
您是否尝试过通过 telnet 测试您的凭据?您可以查看如何测试in this video。我真希望你指定的用户名和密码是测试数据...
-
确实 - 使用
nc -w 1 smtp.sendgrid.net 465命令检查您的 SSL 端口号。服务器未在该端口上侦听。但是它侦听 25、587 个端口。见Common SMTP port numbers -
@JimWright 现在我在我的帐户中的 sendgrip 中创建了新的 api 密钥和密码我没有签入 telnet,因为我无法访问受管理员保护的控制面板。
-
@sakthi 这与您的控制面板无关。查看我上面链接的视频,以测试发送电子邮件,以便了解要使用的主机、端口和凭据。