rss search

Facebook email module via Heroku

line

At last, after a few days struggling, Alhamdulillah, now I can use Sendgrid (a cloud-based messaging system) with “swiftmailer” to send out email notifications about Tempahan Projektor via Heroku (cloud-based application that offer free https), in DCT’s Facebook’s SewaProjektor page.

The work is quiet tedious as “sendgrid-php”‘s Git submodule (https://github.com/sendgrid/sendgrid-php), was configured to received parameter without swiftmailer attached in “/SendGrid/Smtp.php”:

public function __construct($username, $password)
{
/* check for SwiftMailer,
* if it doesn't exist, try loading
* it from Pear
*/
if (!class_exists('Swift')) {
require_once 'swift_required.php';
}
call_user_func_array("parent::__construct", func_get_args());

I do not have PEAR module in my “heroku”, so the right path must be set out to original swiftmailer application’s file.

So, I de-attached the submodule sendgrid-php (as I cannot commit any changes to the branches directly to sendgrid’s git), and make a folder of my own ‘sendgrid-php-swift’ branch in my local heroku.

Then, I:
$git add sendgrid-php-swift/
$git commit -am “installing sendgrid-php-swift”
$git push heroku

and voila! It is working perfectly. 😉

To call the email function using php, easily use:

Filename:myemail.php
include 'sendgrid-php-swift/SendGrid_loader.php';
$sendgrid = new SendGrid($SENDGRID_username, '$SENDGRID_password');
$mail = new SendGrid\Mail();
$mail->
addTo('$email')->
setFrom('$email2')->
setSubject($subject)->
setText($message)->
setHtml($htmlmsg);
$sendgrid->
web->
send($mail);

Best of luck. 😉

P/S: i) https://blazing-sky-7775.herokuapp.com
ii) https://github.com/dzulaiman/sendgrid-php-swift/


1 comment

line
  1. dumbeldore

    Good job. Tumb up .

    line

Leave a Reply