Works locally, fails on Amazon EC2 instance - empty message?
I've been using the kit via Composer, my code is pretty much what is in the sample (shown below anyway). This set up has worked fine when I test locally (Windows 7, Apache 2.4, PHP 5.6.9) yet it fails when I test using an Amazon EC2 instance (the Amazon AMI, Apache 2.4.18, PHP 5.6.19).
$sendgrid = new SendGrid('[username]', '[password]');
$email = new SendGrid\Email();
$email
->addTo($recipientEmail)
->setFrom('noreply@[domain].com')
->setSubject('New page request')
->setText($message)
->setHtml($message)
;
try {
$sendgrid->send( $email );
} catch(SendGrid\Exception $e) {
foreach($e->getErrors() as $er) {
$alerts[] = $er;
}
}
$message is defined just prior to this code, and I have verified it is populated by dumping it to the screen. Plus it comes through in the email when I test locally. The error occurs on the send() line, and the error message that results is Missing email body. No error occurs locally, only when I run the code on EC2. Makes me wonder if there is some weird interaction happening there. Any thoughts?
Are you using templates?
I haven't done anything to involve templates, so no.
@grantpalin,
In that case, could you please open a ticket at https://support.sendgrid.com? Thanks!
Somehow it now works. I thought to re-upload the code (as there were other unrelated changes) and reran composer, and ran successfully the code in question. I don't think I changed anything of consequence, but there it is. Maybe a fresh copy of the code did it.
Thanks for the follow up @grantpalin!