【问题标题】:mail not send via SMTP API using sendgrid邮件未使用 sendgrid 通过 SMTP API 发送
【发布时间】: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 这与您的控制面板无关。查看我上面链接的视频,以测试发送电子邮件,以便了解要使用的主机、端口和凭据。

标签: php sendgrid


【解决方案1】:

使用 API Keys 通过 SMTP 连接到 SendGrid 时,您需要使用 apikey as the username

此外,由于您刚刚在此处公开共享了该 API 密钥,因此您需要销毁它并创建一个新的。它不再安全。

SendGrid 确实支持端口 465 进行 SSL 连接g,但正如 Jim 所说,您需要 test your connection 并查看您的服务器是否允许该连接。如果没有,请按照该文章的建议尝试不同的端口。 我建议尝试使用 TLS 连接的端口 587。

【讨论】:

  • 上面提到的 api 密钥没有被使用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-15
  • 1970-01-01
  • 2013-09-03
  • 2023-03-16
  • 1970-01-01
  • 2014-03-05
  • 1970-01-01
相关资源
最近更新 更多