我正在尝试使用SendGrid SMTP
服务器从网页上的联系表发送电子邮件。
我已将PHPMailer
安装到Web服务器中并以php形式配置了SMTP
凭据,并且只要接收者("to")
是gmail
帐户,它就可以正常工作。 但是,如果我将该帐户更改为我自己的域之一,即hello@myowndomain.net
,则永远不会收到该电子邮件。
我不知道是否应该在我的SendGrid
帐户或我的php
代码中配置其他功能。
这是我的php代码:
<?php
require_once "vendor/autoload.php";
$mail = new PHPMailer;
//Enable SMTP debugging.
$mail->SMTPDebug = 1;
//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name
$mail->Host = " smtp.sendgrid.net";
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;
//Provide username and password
$mail->Username = "apikey";
$mail->Password = "mySMTPPassword";
//If SMTP requires TLS encryption then set it
//$mail->SMTPSecure = "tls";
//Set TCP port to connect to
$mail->Port = 587;
$mail->From = "test@gmail.com";
$mail->FromName = "Full Name";
$mail->smtpConnect(
array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
"allow_self_signed" => true
)
)
);
$mail->addAddress("hello@myowndomain.net", "Recepient Name");
$mail->isHTML(true);
$mail->Subject = "Contact form";
$mail->Body = "<i>You have received a new message!</i>";
$mail->AltBody = "This is the plain text";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
编辑:
I changed SMTPDebug mode to 2, and it seems everything is OK for me:
2018-08-09 14:08:15 CLIENT -> SERVER: AUTH LOGIN
2018-08-09 14:08:15 SERVER -> CLIENT: 334
2018-08-09 14:08:15 CLIENT -> SERVER: YXBpa2V5
2018-08-09 14:08:15 SERVER -> CLIENT: 334
2018-08-09 14:08:15 CLIENT -> SERVER:
2018-08-09 14:08:16 SERVER -> CLIENT: 235 Authentication successful
2018-08-09 14:08:16 CLIENT -> SERVER: MAIL FROM:<test@gmail.com>
2018-08-09 14:08:16 SERVER -> CLIENT: 250 Sender address accepted
2018-08-09 14:08:16 CLIENT -> SERVER: RCPT TO:<hellomyowndomain.com>
2018-08-09 14:08:16 SERVER -> CLIENT: 250 Recipient address accepted
2018-08-09 14:08:16 CLIENT -> SERVER: DATA
2018-08-09 14:08:16 SERVER -> CLIENT: 354 Continue
2018-08-09 14:08:16 CLIENT -> SERVER: Date: Thu, 9 Aug 2018 07:08:16 -0700
2018-08-09 14:08:16 CLIENT -> SERVER: To: Recepient Name <hellowmyowndomain.com>
2018-08-09 14:08:16 CLIENT -> SERVER: From: Full Name <test@gmail.com>
2018-08-09 14:08:16 CLIENT -> SERVER: Subject: Contact form
2018-08-09 14:08:16 CLIENT -> SERVER: Message-ID: <@localhost>
2018-08-09 14:08:16 CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.26
(https://github.com/PHPMailer/PHPMailer)
2018-08-09 14:08:16 CLIENT -> SERVER: MIME-Version: 1.0
2018-08-09 14:08:16 CLIENT -> SERVER: Content-Type: multipart/alternative;
2018-08-09 14:08:16 CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
2018-08-09 14:08:16 CLIENT -> SERVER:
2018-08-09 14:08:16 CLIENT -> SERVER: This is a multi-part message in MIME
format.
2018-08-09 14:08:16 CLIENT -> SERVER:
2018-08-09 14:08:16 CLIENT -> SERVER: Content-Type: text/plain; charset=us-ascii
2018-08-09 14:08:16 CLIENT -> SERVER:
2018-08-09 14:08:16 CLIENT -> SERVER: This is the plain text
2018-08-09 14:08:16 CLIENT -> SERVER:
2018-08-09 14:08:16 CLIENT -> SERVER: Content-Type: text/html; charset=us-ascii
2018-08-09 14:08:16 CLIENT -> SERVER:
2018-08-09 14:08:16 CLIENT -> SERVER: <i>You have received a new message!</i>
2018-08-09 14:08:16 CLIENT -> SERVER:
2018-08-09 14:08:16 CLIENT -> SERVER:
2018-08-09 14:08:16 CLIENT -> SERVER:
2018-08-09 14:08:16 CLIENT -> SERVER:
2018-08-09 14:08:16 CLIENT -> SERVER: .
2018-08-09 14:08:16 SERVER -> CLIENT: 250 Ok: queued as
2018-08-09 14:08:16 CLIENT -> SERVER: QUIT
2018-08-09 14:08:16 SERVER -> CLIENT: 221 See you later
Message has been sent successfully
答案 0 :(得分:0)
似乎问题出在我的代码或配置中,而不是我的SMTP服务器使用的IP中。我的IP已被列入黑名单,这阻止了我的电子邮件。当您使用免费套餐(共享IP)时,可能会发生这种情况:https://sendgrid.com/docs/Classroom/Deliver/Undeliverable_Email/what_do_i_do_if_im_blacklisted.html