我正在尝试通过SendGrid,以便通过我的网站上的联系方式发送电子邮件。我的代码没有抛出任何错误,但是电子邮件仍未传递。没有产生202状态码,因此结果返回为假
请,外面的PHP专家可以快速浏览一下,看看我在哪里出错。因为我没有收到任何错误,所以我完全迷路了!
require("sendgrid-php/sendgrid-php.php");
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$company = $_POST['company'];
$message = $_POST['message'];
$FROM_EMAIL = 'test@test.com';
$TO_EMAIL = 'test@test.com';
$subject = "Contact Form";
$from = new SendGrid\Email(null, $FROM_EMAIL);
$to = new SendGrid\Email(null, $TO_EMAIL);
$content = new SendGrid\Content("text/plain",$name, $email, $phone, $company, $message);
$mail = new SendGrid\Mail($subject, $from, $to, $content);
$sendgrid = new \SendGrid(getenv('API-KEY'));
$response = $sendgrid->client->mail()->send()->post($mail);
if ($response->statusCode() == 202) {
// Successfully sent
echo 'done';
} else {
echo 'false';
}
}