【问题标题】:PHPmailer how to show messagePHPmailer如何显示消息
【发布时间】:2016-06-13 20:30:13
【问题描述】:

在我的表单中单击发送后如何显示成功消息?我的 phpmailer 正在工作,但我还想点击发送以重定向到我的主页(index.html)并显示我的消息 div。这是我的 php 代码。

<?php
require 'phpmailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'mail.xxxxxxx.pl';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'xxxxx@xxxxxxxx.pl';                 // SMTP username
$mail->Password = 'password';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom($email, $name);
$mail->addAddress('xxxx@gmail.com', 'xxxxxxxx');     // Add a recipient              // Name is optional

$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = $subject;
$mail->Body    = 'Body test';


if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
   header('Location: index.html');

}

这是我显示/隐藏 div 成功的 Jquery 代码:

$('.box-up').animate({top : 150}, 'normal').delay(3000).animate({top : -500}, 'normal');

【问题讨论】:

  • 您必须将消息存储在某个地方,然后安排您的 html 页面显示它。

标签: php jquery phpmailer


【解决方案1】:

您可以在请求中发送额外的参数:

header('Location: index.php?r=1');

然后在您的索引页面中获取参数并使用它来显示框:

<script>
    var result="<?php echo $_GET['r']; ?>";

    if(parseInt(result)){
        $('.box-up').animate({top : 150}, 'normal').delay(3000).animate({top : -500}, 'normal');
    }
</script>

希望这会有所帮助。

【讨论】:

  • 所以我必须将 index.html 保存为 index.php 并将此代码添加到我的 js 文件中?
  • 你应该调试才能知道问题出在哪里,例如显示alert(result);;
  • 当我使用警报进行调试时,返回数字 1,所以这应该可以工作,但这个 jquery 不起作用。在我的本地主机中,这个 jquery 工作正常显示和隐藏 div。
猜你喜欢
  • 1970-01-01
  • 2019-08-07
  • 2011-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-07
  • 1970-01-01
  • 2011-06-15
相关资源
最近更新 更多