簡體   English   中英

SendGrid郵件未發送(Web和SMTP)

[英]SendGrid mail not sending (web and smtp)

我已經嘗試了一段時間,以使我的電子郵件可以使用SendGrid發送。 我已經設置了一個測試PHP腳本:

<?php

require_once('../resources/functions/sendgrid/lib/SendGrid.php');
SendGrid::register_autoloader();
require_once('../resources/functions/unirest/lib/Unirest.php');

$sendgrid = new SendGrid('my_username', 'my_password');

$sendgrid_email = new SendGrid\Email();
$sendgrid_email->addTo('my_email@gmail.com')->
                setFrom('Name <noreply@my_domain.co.uk>')->
                setSubject('Name | Test Mail')->
                setText("TEST MESSAGE");
$sendgrid->smtp->send($sendgrid_email);

echo 'mail sent';

?>

我已經嘗試過使用web和smtp方法,這兩種方法都到達“已發送郵件”回顯,但實際上都沒有出現在我的收件箱中,當我檢查SendGrid帳戶時,我仍然有0封已發送電子郵件。

編輯:

好的,我知道了。 刪除了“名稱”,將其更改為“ noreply@my_domain.co.uk”。 但是,我想使用第一種方法定義名稱-可以這樣做嗎?

另一個編輯:

好吧,尼克Q的答案解決了我遇到的其他問題。 對於任何想知道的人,您都可以通過將setFrom設置為電子郵件[setFrom(“ noreply@example.com”)]然后使用setFromName [setFromName(“ Example”)] 。

調用SendGrid::register_autoloader(); 之后還需要Unirest。

否則您的腳本看起來不錯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM