整PHP contact form遇到问题
时间:2012-06-08
来源:互联网
我在帮公司整一个网页, 用PHP contact form整一个inquiry page, 俾人填名、电话、email等, 想按”send”就会将d资料变成个email send 去我个mail box度,
而我其实唔算好识呢d, 个inquiry page都系用呢个网讲ge野改出泥ge: http://myphpform.com/php-form-tutorial.php
==============================================================
<?php
date_default_timezone_set('Asia/Hong_Kong');
ini_set("sendmail_from","*******@yahoo.com.hk"
;
ini_set("SMTP","smtp.wtt-mail.com"
;
/* Set e-mail recipient */
$myemail = "****************@yahoo.com.hk";
/* Check all form inputs using check_input function */
$company = check_input($_POST['company'], "enter your company's name"
;
$person = check_input($_POST['person'], "enter your name");
$tel = check_input($_POST['tel'], "enter your contact number");
$email = check_input($_POST['email'], "Please enter your E-mail");
$subject = "Online Enquiry";
/*$content = check_input($_POST['content'], "Write your content");*/
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* If URL is not valid set $website to empty */
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website))
{
$website = '';
}
/* Let's prepare the message for the e-mail */
$message = "Hello!
CTC-940 contact form has been submitted by:
Company Name: $company
Contact Person: $person
Tel: $tel
E-mail: $email
Content:
$content
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
/* Location: http://www.******.com/ */
header("ThankYou.html");
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
correct the following error:
<?php
ob_end_flush();
exit();
}
?>
==============================================================
我send完想个网跳去thank you page度, 但会出现句 ”Cannot modify header information – header already sent by (output started at C:\inetpub\wwwroot\contant2.php:1) in C:\inetpub\wwwroot\contant2.php on line 45”
Line45姐系「header("ThankYou.html");」呢行
上网搵过解决方法, 试咗
1. 我个php.ini的output_buffering一直是on的
2. 在header后加exit();
3. 加上同ob_end_flush();
个email系send到, 填漏资料都识跳去error page, 但就系去唔到页thank you page…都系Cannot modify header information(略)
请问系唔系我改得唔啱?有咩解决方法呢?
而我其实唔算好识呢d, 个inquiry page都系用呢个网讲ge野改出泥ge: http://myphpform.com/php-form-tutorial.php
==============================================================
<?php
date_default_timezone_set('Asia/Hong_Kong');
ini_set("sendmail_from","*******@yahoo.com.hk"

ini_set("SMTP","smtp.wtt-mail.com"

/* Set e-mail recipient */
$myemail = "****************@yahoo.com.hk";
/* Check all form inputs using check_input function */
$company = check_input($_POST['company'], "enter your company's name"

$person = check_input($_POST['person'], "enter your name");
$tel = check_input($_POST['tel'], "enter your contact number");
$email = check_input($_POST['email'], "Please enter your E-mail");
$subject = "Online Enquiry";
/*$content = check_input($_POST['content'], "Write your content");*/
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* If URL is not valid set $website to empty */
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website))
{
$website = '';
}
/* Let's prepare the message for the e-mail */
$message = "Hello!
CTC-940 contact form has been submitted by:
Company Name: $company
Contact Person: $person
Tel: $tel
E-mail: $email
Content:
$content
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
/* Location: http://www.******.com/ */
header("ThankYou.html");
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
correct the following error:
<?php
ob_end_flush();
exit();
}
?>
==============================================================
我send完想个网跳去thank you page度, 但会出现句 ”Cannot modify header information – header already sent by (output started at C:\inetpub\wwwroot\contant2.php:1) in C:\inetpub\wwwroot\contant2.php on line 45”
Line45姐系「header("ThankYou.html");」呢行
上网搵过解决方法, 试咗
1. 我个php.ini的output_buffering一直是on的
2. 在header后加exit();
3. 加上同ob_end_flush();
个email系send到, 填漏资料都识跳去error page, 但就系去唔到页thank you page…都系Cannot modify header information(略)
请问系唔系我改得唔啱?有咩解决方法呢?
作者: JK0213 发布时间: 1970-01-01
你应该漏左location
header("location: ThankYou.html");
http://php.net/manual/en/function.header.php
[ 本帖最后由 豪狗仔 於 2012-6-8 08:28 PM 编辑 ]
header("location: ThankYou.html");
http://php.net/manual/en/function.header.php
[ 本帖最后由 豪狗仔 於 2012-6-8 08:28 PM 编辑 ]
作者: 豪狗仔 发布时间: 1970-01-01
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28