Call SendGrid::register_autoloader();
after also requiring Unirest.
Otherwise your script looks good.
Question
I've been trying for a while to get my emails to send using SendGrid. I've set up a test PHP script:
<?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.
EDIT:
Ok, so I got it working. Removed the "name ", changed it to just "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. And for anyone who is wondering, the way you set a from name (i.e Example ) is by having setFrom as just the email [setFrom("noreply@example.com")] and then using setFromName [setFromName("Example")].
Solution
Call SendGrid::register_autoloader();
after also requiring Unirest.
Otherwise your script looks good.