Use SendGrid with Jelastic and PHP

SendGrid is a reliable and scalable cloud-based email infrastructure with flexible APIs that allows you to easily integrate it to your app. Jelastic and SendGrid interconnection gives you an opportunity to send the emails directly from your PHP application without the necessity to support the custom email system.

In the following instruction we will examine a simple example of SendGrid integration with PHP application hosted with Jelastic PAI.

A. Sign Up for SendGrid

The first thing you should do is to create a new account at SendGrid. For the first try of Jelastic and SendGrid integration you can choose a free pricing plan, that allows you to send mailings with a limitation in 200 emails per day.

Note that some time is needed for the account to be verified.

Remember your username and password after registration, you’ll need them for configuring application example below.

B. Create an environment

  • Login to Jelastic Manager and press Create Environment button. Then select PHP language wizard tab and specify environment name, sendgrid-php in our case.
    create sendgrid environment

  • Click Upload button in Deployment Manager. Sample SendGrid application, bundled with SendGrid PHP library, is hosted at GitHub, therefore you can use the direct link for archive uploading: upload sendgrid

  • After the archive is uploaded, it will be listed in the packages panel. Press Deploy to.. button next to archive and select environment you’ve created in the previous steps.

deploy sendgrid

  • Type context in the opened window (in case you need it) and press Deploy.

C. Sample Application Configuring

After sample application is deployed, you can configure it and specify your SendGrid login and password.

  • Press Config button alongside the Apache server.

apache configuration

  • You’ll see the list of folders and configuration files. Navigate to the webroot > {context_name} folder and open index.php file.

Edit the circled below strings to specify your SendGrid account username, password, and email you want to send mailings from.
sendgrid settings

Don’t forget to press Save button.

D. Checking the result

  1. Find your SendGrid environment at the dashboard and open it (Open in browser button near the application context). open sendgrid

  2. You’ll see the simple basic form for emails sending. State the recipient in the To: field, subject and mailing text in the Subject: and Content: fields respectively. Click Send. sending sendgrid form

  3. Just in a few minutes the sent email will appear in the inbox of recipient. sendgrid email

That’s all! For now you are able to send up to 200 emails per day via your PHP application hosted with Jelastic. More info about plenty of additional features you can find in the complete SendGrid documentation. Enjoy!