如何使用PHP在heroku上发送电子邮件

如何使用PHP在heroku上发送电子邮件

本文介绍了如何使用PHP在heroku上发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了PHP应用程序并使用heroku进行了部署.在应用程序中,我有联系表,可以将邮件发送到我的Gmail帐户.为了实现这一点,我编写了以下PHP代码

I have created PHP app and deployed using heroku. In the app, I have contact form to send mails to my gmail account. To implement this, I have written the following PHP code

<?php
   $to = "[email protected]";
   $subject = "This is subject";
   $message = "This is simple text message.";
   $header = "From:[email protected] \r\n";
   $retval = mail ($to,$subject,$message,$header);
   if( $retval == true ){
      echo "Message sent successfully...";
   }else{
      echo "Message could not be sent...";
   }
?>

我的php脚本正在执行.但是它没有发送邮件,而是显示Message could not be sent.任何人都可以使用PHP来实现联系表单吗?

My php script is executing. But it is not sending mail instead it is showing up Message could not be sent. Can any one help to implement contact form using PHP?

推荐答案

Heroku不允许发送电子邮件,必须使用外部SMTP服务器.

Heroku doesnt allow send e-mails, you must use external SMTP server.

要从部署到Heroku的应用程序发送电子邮件,请使用外部SMTP服务." https://devcenter.heroku.com/articles/smtp

"To send emails from applications deployed to Heroku, use an external SMTP service."https://devcenter.heroku.com/articles/smtp

此处介绍了如何发送发送SMTP的电子邮件:使用PHP从SMTP服务器发送电子邮件

How to send e-mails throw SMTP is described here: Sending email with PHP from an SMTP server

这篇关于如何使用PHP在heroku上发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 14:16