如何清除$ _POST元素但是仍然在PHP中保留几个变量?

时间:2017-08-19 22:50:16

标签: php post

我想通过刷新页面来停止垃圾邮件联系表单的功能。是的,我尝试了这里提到的几种方法来避免这种情况,但它没有用。好吧,部分工作。我使用$ _POST并指向表单上的同一页面(index.php)将其重定向到同一页面,然后打印成功或错误消息。我设法修复了刷新垃圾邮件的事情,但后来我也失去了成功/错误消息。帮助我解决它,以便您不能通过刷新页面垃圾邮件,仍然看看邮件是否成功发送。这是我的代码:

<?php
if(isset($_POST['submit'])) 
{

$message=
'Full Name: '.$_POST['fullname'].'<br />
Subject:    '.$_POST['subject'].'<br />
Phone:  '.$_POST['phone'].'<br />
Email:  '.$_POST['emailid'].'<br />
Comments:   '.$_POST['comments'].'
';
require "PHPMailer-master/class.phpmailer.php"; //include phpmailer class

// Instantiate Class  
$mail = new PHPMailer();  

// Set up SMTP  
$mail->IsSMTP();                // Sets up a SMTP connection  
$mail->SMTPAuth = true;         // Connection with the SMTP does require 
authorization    
$mail->SMTPSecure = "ssl";      // Connect using a TLS connection  
$mail->Host = "smtp.gmail.com";  //Gmail SMTP server address
$mail->Port = 465;  //Gmail SMTP port
$mail->Encoding = '7bit';

// Authentication  
$mail->Username   = "xxx@xxx.xx"; // Your full Gmail address
$mail->Password   = "xxxxx"; // Your Gmail password

// Compose
$mail->SetFrom($_POST['emailid'], $_POST['fullname']);
$mail->AddReplyTo($_POST['emailid'], $_POST['fullname']);
$mail->Subject = "AL Service Contact Form";      // Subject (which isn't required)  
$mail->MsgHTML($message);

// Send To  
$mail->AddAddress("post@alservice.no", "AL Service"); // Where to send it - Recipient
$result = $mail->Send();        // Send! 
$message = $result ? '<div class="ctrdiv fntsucc"><strong>Meldingen ble sendt! Vi kontakter deg snart.</strong></div><br>' : '<div class="ctrdiv fnterr"><strong>Meldingen ble ikke sendt! Vennligst prøv en gang til.</strong></div><br>';  
unset($mail);

}
?>

<?php if(!empty($message)) echo $message; ?>

0 个答案:

没有答案