Sendgrid - Receiver无法接收使用php发送的电子邮件

问题描述 投票:2回答:1

这是我的send_email.php

require("../sendgrid-php/sendgrid-php.php");

$from = new SendGrid\Email("Example User", "[email protected]");
$subject = "Sending with SendGrid is Fun";
$to = new SendGrid\Email("Example User", "[email protected]");
$content = new SendGrid\Content("text/plain", "and easy to do anywhere, even with PHP");
$mail = new SendGrid\Mail($from, $subject, $to, $content);

$apiKey = ('MY_API_KEY');
$sg = new \SendGrid($apiKey);

$response = $sg->client->mail()->send()->post($mail);
echo $response->statusCode();
print_r($response->headers());
echo $response->body();

当我尝试运行“send_email.php”时,响应是202,这意味着它是正确的?当我检查我的Sendgrid活动日志时,它会显示“Delivered”。但是当接收者检查他/她的Gmail时,他/她没有收到任何东西。 (顺便说一句,我在localhost中测试它)。请帮我。非常感谢你。

php sendgrid
1个回答
0
投票

如果活动日志显示已交付或响应为“202”,则交付日期。检查垃圾邮件文件夹或垃圾邮件。如果邮件过滤器意外删除了垃圾,请检查垃圾箱。在我的情况下,我自己收到的邮件很晚。但我使用转移邮件。

include "/swift/SmtpApiHeader.php";
include "/swift/lib/swift_required.php";

$sendgrid_username = 'xxxx';
$sendgrid_password = 'xxxx';
$to = '[email protected]';

$transport  = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587);
$transport->setUsername($sendgrid_username);
$transport->setPassword($sendgrid_password);

$mailer     = Swift_Mailer::newInstance($transport);

$message    = new Swift_Message();
$message->setTo($to);
$message->setCc("[email protected]",);
$message->addBcc("[email protected]");
$message->setFrom($to);
$message->setSubject("Reg: Pending work");

$msg = "Dear worker, Kindly update me the status of the work. Best Regards";

$message->setBody($msg);

try {
  $response = $mailer->send($message);
  print_r($response);
} catch(\Swift_TransportException $e) {
  print_r($e);
  print_r('Bad username / password');
} 
© www.soinside.com 2019 - 2024. All rights reserved.