如何使联系表单向用户发送确认电子邮件


How to make a contact form send a confirmation email to the user?

这就是我目前所拥有的。

 $full_name = $_REQUEST['full_name'] ;         
 $company = $_REQUEST['company'] ;       
 $abn = $_REQUEST['abn'] ;     
 $customer_number = $_REQUEST['customer_number'] ;     
 $about = $_REQUEST['about'] ;     
 $areacode = $_REQUEST['areacode'] ;     
 $telephone = $_REQUEST['telephone'] ;         
 $email = $_REQUEST['email'] ;     
 $message = $_REQUEST['message'] ;     
 $body =" Full Name: ".$full_name."'n
Company: ".$company."'n                 
ABN: ".$abn."'n    
Customer Number: ".$customer_number."'n
About: ".$about."'n       
Area Code: ".$areacode."'n      
Telephone: ".$telephone."'n     
Email: ".$email."'n                     
Message: ".$message;
$to = "$email";
 mail( "info@rentforbusiness.com.au", "Contact Us Form", $body, "From: $email" );

就像你为自己做的那样。

mail($email, "Thanks For Resistering", $a_thank_you_message, "From: info@rentforbusiness.com.au" );

在数据库中创建一个表。它应包含以下字段:

  • id(自动递增)
  • 电子邮件
  • 消息
  • 确认

当用户发布表单时,不要将邮件发送到您的电子邮件,而是需要创建随机确认码(例如使用 uniqid):

$confirmation = uniqid();

然后将用户电子邮件、消息文本和确认代码添加到表中,并向用户发送电子邮件:

$url = "http://".$_POST["SERVER_NAME"].
  "/confirmation.php?confirmation=$confirmation'>";
mail($email, "Confirmation", 
 "Please press the following link to confirm your message: 
 <a href='http://$url'>confirm</a>.");

confirmation.php文件中,使用$_GET["confirmation"]变量,在表中搜索匹配的记录,从中获取电子邮件和消息,并将此数据发送到您的电子邮件。如果需要,您可以在它之后从数据库中删除条目。