2016-06-13 144 views
1

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

<?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 = '[email protected]';     // 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('[email protected]', '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'); 

} 

这是我的jQuery代码,显示/隐藏DIV更迭:

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

你必须在某处存储消息,然后安排你的html页面来显示它。 –

回答

0

您可以发送额外的参数,你的要求:

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> 

希望这会有所帮助。

+0

所以我必须将index.html保存为index.php,并将此代码添加到我的js文件中? –

+0

是的,这是真的... –

+0

好吧,我尝试了很多次,但这不工作; /嗯... –