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

sun*_*tha 6 php heroku

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

<?php
   $to = "to@gmail.com";
   $subject = "This is subject";
   $message = "This is simple text message.";
   $header = "From:from@yantranet.com \r\n";
   $retval = mail ($to,$subject,$message,$header);
   if( $retval == true ){
      echo "Message sent successfully...";
   }else{
      echo "Message could not be sent...";
   }
?>
Run Code Online (Sandbox Code Playgroud)

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

Hon*_*nza 6

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

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

如何发送电子邮件抛出SMTP在此处描述:使用PHP从SMTP服务器发送电子邮件