每次在提交表单数据后刷新页面时我们如何限制发送邮件 [英] how we restrict to send mail every time the page is refreshed after submit form data
本文介绍了每次在提交表单数据后刷新页面时我们如何限制发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- >>我在php中创建了一个表单页面。
- >>点击提交按钮后,它会重定向到另一个php页面(sendmail.php)
- >>每次用户刷新页面后,每次都会发送邮件。
请在表格提交后帮助我们限制发送邮件。
sendmail.php页面如下
< !DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // EN http:// www。 w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< html xmlns = http ://www.w3.org/1999/xhtml >
< head >
< / head >
< body >
<? php
if(!empty($ _ REQUEST [email]) )
{
// < span class =code-summarycomment> EDIT 2 LINES BELOW AS REQUIRED
$ email_to = kadian2010 @ gmail.com ;
$ email_subject = 接纳查询详细信息 ;
function 死亡($ error) {
// 您的 错误 代码 < span class =code-summarycomment>可以 go 此处
echo 我们 very 抱歉, 但 < span class =code-summarycomment> error(s) 找到 with 表格 你 已提交。 ;
echo 这些 错误 出现 。< br / > < br / > 跨度>;
echo $ error。< br / > < br / > 跨度>;
echo请返回并修复这些错误。< br / > < br / > ;
die();
}
//验证预期数据存在
if(!isset($ _ REQUEST ['name'])||
!isset($ _ REQUEST ['email '])||
!isset($ _ REQUEST ['phone'])||
!isset($ _ REQUEST ['course'])||
!isset($ _ REQUEST [' city'])||
!isset($ _ REQUEST ['comments'])||
!isset($ _ REQUEST ['security_code'])){
death('对不起' ,但您提交的表单似乎有问题。');
}
$ first_name = $ _REQUEST ['name']; //必需
$ email_from = $ _REQUEST ['email']; //必需
$ telephone = $ _REQUEST ['phone']; //必需
$ course = $ _REQUEST ['course']; //必需
$ city = $ _REQUEST ['city']; //必需
$ comments = $ _REQUEST ['comments']; //不需要
$ security = $ _REQUEST ['security_code']; //不需要
$ email_message =表格详情如下。\ n \\ n;
函数clean_string($ string){
$ bad = array(content-type,bcc:,to:,cc:,href);
返回str_replace($ bad,,$ string);
}
$ email_message。=名字:.clean_string($ first_name)。\ n;
$ email_message。=电子邮件:。clean_string($ email_from)。\ n;
$ email_message。=电话:.clean_string($ telephone)。\ n;
$ email_message。=课程:。makean_string($ course)。\ n;
$ email_message。=城市:.clean_string($ city)。\ n;
$ email_message。=评论:.clean_string($ comments)。\ n;
$ email_message。=Security_Code:。cleanantring($ security)。\ n;
//创建电子邮件标头
$ headers ='From:'。$ email_from。\\\\ n。
'回复:'。$ email_from。\\\\ n。
'X-Mailer:PHP /'。 phpversion();
邮件($ email_to,$ email_subject,$ email_message,$ headers);
echo感谢您与我们联系。我们会尽快与您联系。;
}
else {
echo请先纠正填写查询表格;
}
?>
< br < span class =code-keyword> / > < br >
< a href = http://admissioncart.dx.am/contact-us.php > 点击此处< / a > 联系我们
< / body >
< / html >
解决方案
_REQUEST [email])) < span class =code-summarycomment>
{
// 编辑 2 LINES BELOW AS REQUIRED
< span class =code-summarycomment>
email_to = kadian2010@gmail.com ;
email_subject = 接纳查询详细信息 ;
function 死亡(
->> i hv created a form page in php.
->> After click on the submit button it redirect to another php page(sendmail.php)
->> every time the user refresh the page after submit it send a mail every time.
Please help how we restrict to send mail after once the form submit.
The sendmail.php page is as below
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<?php
if(!empty($_REQUEST["email"]))
{
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "kadian2010@gmail.com";
$email_subject = "Admission query details";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_REQUEST['name']) ||
!isset($_REQUEST['email']) ||
!isset($_REQUEST['phone']) ||
!isset($_REQUEST['course']) ||
!isset($_REQUEST['city']) ||
!isset($_REQUEST['comments']) ||
!isset($_REQUEST['security_code'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_REQUEST['name']; // required
$email_from = $_REQUEST['email']; // required
$telephone = $_REQUEST['phone']; // required
$course = $_REQUEST['course']; // required
$city = $_REQUEST['city']; // required
$comments = $_REQUEST['comments']; // not required
$security = $_REQUEST['security_code']; // not required
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Course: ".clean_string($course)."\n";
$email_message .= "City: ".clean_string($city)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
$email_message .= "Security_Code: ".clean_string($security)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
echo"Thank you for contacting us. We will be in touch with you very soon.";
}
else{
echo"Please first fill the Enquiry Form correctively";
}
?>
<br /><br>
<a href="http://admissioncart.dx.am/contact-us.php">Click here</a> to Contact Us
</body>
</html>
解决方案
_REQUEST["email"])) { // EDIT THE 2 LINES BELOW AS REQUIRED
email_to = "kadian2010@gmail.com";
email_subject = "Admission query details"; function died(
这篇关于每次在提交表单数据后刷新页面时我们如何限制发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文