如何使一个简单的PHP应用程序发送来自heroku雪松堆栈的电子邮件? [英] how to make a simple php app send emails from heroku cedar stack?
问题描述
我有一个非常简单的php网站,它有一个使用php mail()函数发送电子邮件的联系表单。我如何在heroku上托管?我应该使用哪个附加组件,以及如何将它设置为使用php?
以下是我为解决相同问题所做的工作:
1.您需要使用安装pear包邮件和Net_SMTP的定制buildpack。您可以使用我通过运行以下命令创建的那个:
heroku配置:添加BUILDPACK_URL = https://github.com /antonyevans/heroku-buildpack-php.git
关键更改是添加了行:
php / bin / pear install Mail
php / bin / pear install Net_SMTP
进入bin / compile。
2.然后您需要告诉您的应用程序加载邮件包:
require_once'Mail.php';
3.最后,heroku阻止邮件端口,因此您需要配置为使用外部邮件服务器。例如,如果您添加了SendGrid插件('heroku addons:add sendgrid:starter'),那么您可以使用以下内容:
$ wgSMTP = array(
'host'=>'tls://smtp.sendgrid.net',
'IDHost'=>'heroku.com',
'port '=> 587,
'username'=> getenv(SENDGRID_USERNAME),
'password'=> getenv(SENDGRID_PASSWORD),
'auth'=>真
);
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?
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
);
这篇关于如何使一个简单的PHP应用程序发送来自heroku雪松堆栈的电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!