how to make a simple php app send emails from heroku cedar stack?

好久不见. 提交于 2019-11-29 17:51:35

问题


I have a very simple php website, that has a contact form that uses the php mail() function to send emails. How can i host this on heroku? wich add-on should i use, and how do i set it to work with php?


回答1:


Here's what I did to solve this same problem:

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
 );


来源:https://stackoverflow.com/questions/13041733/how-to-make-a-simple-php-app-send-emails-from-heroku-cedar-stack

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!