您好,我正在尝试制作一个弹出式联系表格,用于在 heroku 和 gmail 上发送邮件,因为它的邮件服务器是一个链接。弹出部分是好的,但它不能发送邮件帮助我,请找出问题。这个想法是使用 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>
进程.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);
*/
?>