inquiry page send email, 喺php檔

2012-06-05 10:54 pm
我在幫公司整一個網頁, 要整一個inquiry page, 俾人填一個form (e.g. 名、電話、email等), 按”send”就會將d資料變成個email send 去我個mail box度, 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 46” 好似係話我個php檔ge header有問題…redirect唔到…我應該點做??

以下係個php檔
”☞☞☞”指住ge係line 46
<?php ob_start(); ?>


<?php
date_default_timezone_set('Asia/Hong_Kong');
ini_set("sendmail_from","sales@*********.com");
ini_set("SMTP","smtp.wtt-mail.com");

/* Set e-mail recipient */
$myemail = "sales@*********.com";
/* Check all form inputs using check_input function */
$company = check_input($_POST['company'], "Please enter your company's name");
$person = check_input($_POST['person'], "Please enter your name");
$tel = check_input($_POST['tel'], "Please enter your contact number");
$email = check_input($_POST['email'], "Please enter your E-mail");
$subject = "Online Enquiry";
/*$contant = check_input($_POST['content'], "Write your comments");*/

/* 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:
$comments
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.htm');
ob_end_flush();
exit();
更新1:

function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; }

更新2:

function show_error($myError) { ?> Order form error

更新3:

Order form error

更新4:

仲有function show error同error page...太長放唔到...><有需要我再試吓放出泥...

回答 (1)

2012-06-11 5:31 am
✔ 最佳答案
之前讀完個課程,課程有教到解決方法
我覺得導師教得幾好
有免費試睇
詳細可以參考PHP + MySQL網站架設入門課程
http://www.systematic.com.hk/php_mysql.htm


收錄日期: 2021-04-29 22:47:36
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20120605000051KK00254

檢視 Wayback Machine 備份