sendgrid-php icon indicating copy to clipboard operation
sendgrid-php copied to clipboard

Works locally, fails on Amazon EC2 instance - empty message?

Open grantpalin opened this issue 10 years ago • 5 comments

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?

grantpalin avatar Apr 14 '16 23:04 grantpalin

Are you using templates?

thinkingserious avatar Apr 18 '16 18:04 thinkingserious

I haven't done anything to involve templates, so no.

grantpalin avatar Apr 18 '16 20:04 grantpalin

@grantpalin,

In that case, could you please open a ticket at https://support.sendgrid.com? Thanks!

thinkingserious avatar Apr 19 '16 15:04 thinkingserious

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.

grantpalin avatar Apr 19 '16 21:04 grantpalin

Thanks for the follow up @grantpalin!

thinkingserious avatar May 18 '16 18:05 thinkingserious