1

I have a php app which is deployed on Heroku. How do I get the PEAR mail package to work for my app? I see two main options: 1) install pear mail package on heroku 2) Bundle the package into my app before deployment

Unfortunately I'm more of a rails guy so not sure how to do either of these (or which one is right).

Thanks, Antony

TechnoTony
  • 1,587
  • 1
  • 15
  • 24
  • This solution to this question would also work for me (though I'm looking for a more general solution): http://stackoverflow.com/questions/13041733/how-to-make-a-simple-php-app-send-emails-from-heroku-cedar-stack – TechnoTony Nov 29 '12 at 00:09

1 Answers1

4

OK, I finally figured this out myself. Here's what I did:

1.You need to use a custom buildpack which installs the pear packages mail and Net_SMTP. You can use the one I created by running the following command:

heroku config:add BUILDPACK_URL=https://github.com/antonyevans/heroku-buildpack-php.git

The key changes are the addition of the lines:

php/bin/pear install mail
php/bin/pear install Net_SMTP

Into bin/compile.

2.Then you need to tell your application to load the mail package:

require_once 'Mail.php';

3.Finally heroku blocks the mail port so you need to configure to use an external mail server. For example if you have added the SendGrid addon ('heroku addons:add sendgrid:starter') then you could use the following:

$wgSMTP = array(
    'host' => 'tls://smtp.sendgrid.net',
    'IDHost' => 'heroku.com',
    'port' => 587,
    'username' => getenv("SENDGRID_USERNAME"), 
    'password' => getenv("SENDGRID_PASSWORD"),
    'auth' => true
 );
TechnoTony
  • 1,587
  • 1
  • 15
  • 24
  • TechnoTony's answer is correct. But buildpack he posted is outdated. I followed his advice and modified the current one. I've placed it for use at `https://github.com/blindstuff/heroku-buildpack-php.git` – blindstuff Jun 24 '15 at 22:42