【问题标题】:Heroku + Gmail SMTP + PHP mail in popup contact form弹出联系表中的 Heroku + Gmail SMTP + PHP 邮件
【发布时间】:2017-08-03 15:43:18
【问题描述】:

您好,我正在尝试制作一个在 heroku 和 gmail 上发送邮件的弹出式联系表单,因为这里的邮件服务器是 link。弹出部分是好的,但它不能发送邮件帮助我,请找出问题。这个想法是使用 gmail 作为 heroku 的第三方服务器,我理解这是可能的。感谢您的帮助

index.html 文件 js部分

 <!-- contact form pop -->
<script>
      $(document).ready(function () {
          $("input#submit").click(function(){
             $.ajax({
                         type: "POST",
                         url: "process.php", //process to mail
                         data: $('form.contact_body').serialize(),
                                 success: function(msg){
                                 $("#thanks").html(msg) //hide button and show thank you
                                 $("#contact").modal('hide'); //hide popup
                                 },
                                 error: function(){
                                        alert("sorry the message could not be send");
                                 }
                               });
                  });
             });
  </script>

标记部分

      <div class="modal-body">
        <form class="contact_body" name="contact_body">
          <label class="label" for="form_name">Your Name</label><br>
          <input type="text" name="form_name" id="form_name" class="input-xlarge"><br>
          <label class="label" for="form_email">Your E-mail</label><br>
          <input type="form_email" name="form_email" class="input-xlarge"><br>
          <label class="label" for="form_msg">Enter a Message</label><br>
          <textarea name="form_msg" class="input-xlarge"></textarea>
         </form>
       </div>
       <div class="modal-footer">
         <input class="btn btn-success" type="submit" value="Send!" id="submit">
         <a href="#" class="btn" data-dismiss="modal">Nah.</a>
       </div>
     </div>

process.php 文件

<?php

// Pear Mail Library
require_once "Mail.php";

$from = '<from.gmail.com>';
$to = '<to.yahoo.com>';
subject = 'Hi!';
$body = "Hi,\n\nHow are you?";

$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);

$smtp = Mail::factory('smtp', array(
    'host' => 'ssl://smtp.gmail.com',
    'port' => '465',
    'auth' => true,
    'username' => 'moviply.tv@gmail.com',
    'password' => 'pass'
));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
 } else {
echo('<p>Message successfully sent!</p>');
}


/*
$myemail = 'moviply.tv@gmail.com';
if (isset($_POST['name'])) {
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$message = strip_tags($_POST['message']);
echo "<span class=\"alert alert-success\" >Your message has been received. Thanks!      Here   is what you submitted:</span><br><br>";
echo "<stong>Name:</strong> ".$name."<br>";
echo "<stong>Email:</strong> ".$email."<br>";
echo "<stong>Message:</strong> ".$message."<br>";


$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n ".
"Email: $email\n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email";
mail($to,$email_subject,$email_body,$headers);
*/

?>

【问题讨论】:

    标签: php ajax email heroku gmail


    【解决方案1】:

    我的第一个猜测:process.php 顶部的 $to/$from 地址应该是 (a) 真实消息,并且 (b) 如果发件人地址不是您自己的电子邮件地址,那么您可能会失败不要以其他人的身份发送垃圾邮件。

    SendGrid 库使用起来非常简单,但同样应该有一个真实的“发件人”地址(可能是您自己的),否则当 SG 发送到您的 gmail 帐户时,它不会因来自未知的邮件而成为垃圾邮件一遍又一遍的地址。

    (披露,我为 SendGrid 工作)

    【讨论】:

    • 谢谢。 SG是临时解决方案
    【解决方案2】:

    我认为您应该检查您的 Gmail 帐户配置,请在此答案中找到清单:https://stackoverflow.com/a/45477794/1891220

    当您想通过 Gmail smtp 发送电子邮件时,您必须检查两件重要的事情:

    1. 您的应用配置:

      • 主机:smtp.gmail.com
      • 端口:587465(587 用于 tls,465 用于 ssl)
      • 协议:tlsssl
      • 用户:YOUR_USERNAME@gmail.com
      • 密码:YOUR_PASSWORD
    2. 给定的 Gmail 帐户设置:

    【讨论】:

      【解决方案3】:

      恐怕 gmail 目前正在阻止这项服务,必须有其他更简单的解决方案。除非您使用的是谷歌应用程序(现在的价格是每月 5 美元)。

      服务器确实使用 heroku 自己的 Sendgrid 插件给出了 200(ok)的答案。所以一个临时的解决方案是使用 send-grid 并在未来如有必要将其迁移到其他东西,因为它还没有经过我的完全测试。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-08-22
        • 1970-01-01
        • 2019-10-15
        • 2014-04-27
        • 2014-03-29
        • 2012-11-10
        • 1970-01-01
        • 2016-07-14
        相关资源
        最近更新 更多