简体   繁体   English

SendGrid邮件未发送(Web和SMTP)

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

I've been trying for a while to get my emails to send using SendGrid. 我已经尝试了一段时间,以使我的电子邮件可以使用SendGrid发送。 I've set up a test PHP script: 我已经设置了一个测试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';

?>

I've tried this using both the web and smtp methods, both methods get to the "mail sent" echo, yet neither actually appear in my inbox, and when I check my SendGrid account I still have 0 sent emails. 我已经尝试过使用web和smtp方法,这两种方法都到达“已发送邮件”回显,但实际上都没有出现在我的收件箱中,当我检查SendGrid帐户时,我仍然有0封已发送电子邮件。

EDIT: 编辑:

Ok, so I got it working. 好的,我知道了。 Removed the "name ", changed it to just "noreply@my_domain.co.uk". 删除了“名称”,将其更改为“ noreply@my_domain.co.uk”。 However, I want to define the name using the first method - any way of doing this? 但是,我想使用第一种方法定义名称-可以这样做吗?

ANOTHER EDIT: 另一个编辑:

Alright, Nick Q's answer fixed the rest of the issues I was having. 好吧,尼克Q的答案解决了我遇到的其他问题。 And for anyone who is wondering, the way you set a from name (ie Example ) is by having setFrom as just the email [setFrom("noreply@example.com")] and then using setFromName [setFromName("Example")]. 对于任何想知道的人,您都可以通过将setFrom设置为电子邮件[setFrom(“ noreply@example.com”)]然后使用setFromName [setFromName(“ Example”)] 。

Call SendGrid::register_autoloader(); 调用SendGrid::register_autoloader(); after also requiring Unirest. 之后还需要Unirest。

Otherwise your script looks good. 否则您的脚本看起来不错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM