模态形式&;phpmailer问题


modal form & phpmailer issue

我有一个模态表单,我通过图像点击在页面上调用它。模态表单会按照它应该的方式出现,我可以填写信息,点击提交,它会进入"process.php"文件,通过电子邮件发送给我。

process.php文件将返回电子邮件已发送,但从未收到。

当echo声明消息已发送时,也不会返回任何echo。

这是模态

          <a data-toggle="modal" data-target="#myModal" href="#"><img src="http://ashlardev.byethost17.com/images/shoplevel.png" class="img-square pull-right"></a>
      <div class="modal fade custom-class" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <h4 class="modal-title" id="myModalLabel">Complete the form below to setup your <br>FREE account to view Le-Vel Products:</h4>
            </div>
            <div class="modal-body">

              <form id="modal_feedback" method="POST" action="/process.php" accept-charset="UTF-8">
              <p><label>Your Name<strong>*</strong><br>
              <input type="text" autofocus required size="48" name="name" value=""></label></p>
              <p><label>Email Address<strong>*</strong><br>
              <input type="email" required title="Please enter a valid email address" size="48" name="email" value=""></label></p>
              <p><label>Telephone<br>
              <input type="tele" size="48" name="tele" value=""></label></p>
              </form>
            </div>
            <div class="modal-footer">
            *This information will not be shared with anyone other than Le-Vel.
    <a href="/process.php" class="btn btn-success" type="submit" value="Send!" id="submit">Submit</a>
    <a href="index5.html" class="btn btn-success" data-dismiss="modal">Nah.</a>
</div>

以下是process.php中包含的php

<?php
require_once('PHPMailerAutoload.php');
require_once('class.phpmailer.php');
require_once('class.smtp.php');
//include("class.smtp.php"); // optional, gets called from within    class.phpmailer.php if not already loaded

$mail             = new PHPMailer();


$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "smtp.openmailbox.org"; // SMTP server
$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth   = false;                  // enable SMTP authentication
$mail->Host       = "smtp.openmailbox.org"; // sets the SMTP server

$mail->SMTPSecure = 'TLS';                            // Enable encryption, 'ssl' also accepted
$mail->Port = 587;                                    //Set the SMTP port number - 587 for authenticated TLS
$mail->Username   = "username"; // SMTP account username
$mail->Password   = "password";        // SMTP account password

//add the recipient's address here
$myemail = 'my@address.com';
$mail->addAddress('my@address.com', 'Ford Christopher');
//grab named inputs from html then post to #thanks
if (isset($_POST['name'])) {
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$tele = strip_tags($_POST['tele']);
$body = "this is the body of my message: $name, $email, $tele";
$email_subject = "Le-Vel Free Account Information";
//generate email and send!
$headers = 'From: '.$email"'r'n".
'Reply-To: '.$email"'r'n" .
'X-Mailer: PHP/' . phpversion();
@mail($myemail, $email_subject, $body, $headers);
}
if($mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error:  ' . $mail->ErrorInfo;
echo $name;
echo $email;
echo $tele;
echo $body;
} else {
echo 'Message has been sent';
echo $name;
echo $email;
echo $tele;
echo $body;
}

?>

有一系列错误。首先,永远不要使用@抑制您的函数。而是正确测试并处理它:

if(!mail($myemail, $email_subject, $body, $headers)) {
    echo "failed";
}

其次,你的if($mail->send())条件是错误的。你把它们放错了方向:

  • if($mail->send()) {...=TRUE
  • if(!$mail->send()) {...=FALSE

所以你希望你的比较看起来像这样:

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error:  ' . $mail->ErrorInfo;
    //... the rest..
} else {
    echo 'Mail sent successfully';
}

现在来谈谈为什么你的邮件没有发送

由于您的";提交";只是指向process.php页面的<a>链接。

您需要正确地重新构建表单,否则将不会提交任何输入元素。因此不会发送邮件。

<div class="modal fade custom-class" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">Complete the form below to setup your <br>FREE account to view Le-Vel Products:</h4>
            </div>
            <form id="modal_feedback" method="POST" action="/process.php" accept-charset="UTF-8">
                <div class="modal-body">
                    <p><label>Your Name<strong>*</strong><br>
                            <input type="text" autofocus required size="48" name="name" value=""></label></p>
                    <p><label>Email Address<strong>*</strong><br>
                            <input type="email" required title="Please enter a valid email address" size="48" name="email" value=""></label></p>
                    <p><label>Telephone<br>
                            <input type="tele" size="48" name="tele" value=""></label></p>
                </div>
                <div class="modal-footer">
                    *This information will not be shared with anyone other than Le-Vel.
                    <input type="submit" class="btn btn-success" name="submit" value="Send!" id="submit">
                    <a href="index5.html" class="btn btn-success" data-dismiss="modal">Nah.</a>
                </div>
            </form>
        </div>
    </div>
</div>

您会注意到我是如何移动form元素来封装.modal-body&.modal-footer;允许您实际拥有CCD_ 11输入元素。