How to use SendGrid Web API via PHP in Loalhost

I was working on an app for a client and I needed to send email from localhost. The scripting language that I was using was php and I was using WAMP as my server. So the first thing I did was to download the sendgrid php api since I did not have composer. After unzipping the files I placed the sendgrid folder within the root of my project.

There is a nice example on the github page that you can use right away but first you need to setup a couple of things. At the top of the php file you need to add this line:

require("path/to/sendgrid-php/sendgrid-php.php");

Now when you try to send email you will get this error:

cURL error 60: SSL certificate: unable to get local issuer certificate

Since we are sending from localhost we need to setup SSL. These steps apply to WAMP but I think you can easily apply them to other setups.

  1. Download the latest CA Certificate file from here.
  2. Now go to where ever you have installed wamp and place it under: wamp\bin\php\php<version>\extras\ssl
  3. Open php.ini and find this line: curl.cainfo
  4. Uncomment the above line and point it to the cacert.pem file you placed in step 2.
  5. Save the file and restart your WAMP server.

If you try to send mail it should work. For XAMPP server use this solution.