Php 使用sendgrid无法通过SMTP API发送邮件

Php 使用sendgrid无法通过SMTP API发送邮件,php,sendgrid,Php,Sendgrid,邮件未使用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->SMTPAu

邮件未使用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主机


使用API密钥通过SMTP连接到SendGrid时,需要使用
apikey

另外,因为您刚刚在这里公开共享了该API密钥,所以需要销毁它并创建一个新的API密钥。它不再安全了

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

您是否尝试过通过telnet测试您的凭据?您可以看到如何进行测试。我真的希望您指定的用户名和密码是测试数据…事实上-使用
nc-w 1 smtp.sendgrid.net 465
命令检查您的SSL端口号。服务器未在该端口上侦听。然而,它监听25587个端口。请参阅@jimwight now我在我的帐户的sendgrip中创建了新的api密钥和密码。我没有签入telnet,因为我无法访问受admin保护的控制面板。@sakthi这与您的控制面板无关。看看我上面链接的视频,测试发送电子邮件,这样你就知道要使用哪个主机、端口和凭据了。上面提到的api密钥没有被使用