0
我正在嘗試使用發送到特定電子郵件地址的表單設置簡單網站。這個想法是要在電子郵件中發送幾個不同的東西,比如:名字和姓氏,年齡,電子郵件,城市,主題(這是一個包含幾個不同選項的下拉菜單),然後是評論框。.php只將表格的一部分發送到電子郵件地址
我實際上已經花了最後14個小時閱讀並尋找如何讓PHP腳本正常工作以便表單將被髮送的方式。但由於某種原因,我無法弄清楚。
我只是似乎無法得到的形式發送與包括我需要包括的一切。有人能告訴我爲什麼下面的代碼不起作用嗎?
<?php
/* EMAIL RECIPIENT */
$myemail = "[email protected]";
/* 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;
}
/* Check all form inputs using check_input function */
$formName = check_input ($_POST['formName'], "Please enter your First Name");
$formSurname = check_input ($_POST['formSurname'], "Please enter your First Name");
$formAge = check_input ($_POST['formAge'],);
$formEmail = check_input ($_POST['formEmail'], "Please enter your email so we can get back to you");
$formIntent = check_input ($_POST['formIntent'], "Pleas choose a reason for why contact us");
$formIntent = " (MYFORM) " . $formIntent;
$formComment = check_input ($_POST['formComment']);
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $formEmail))
{
show_error("E-mail address not valid");
}
/* The layout for the email and how it will be set up for reading the email. */
$message = "Hello!
Your contact form has been submitted by:
Name: $formName
Age: $formAge
City: $formCity
Email: $formEmail
Comment: $formName
The reason for contact with Mistral is: $formIntent
Comment: $formComment
End of message.
";
/* Send the message using the mail() function */
mail($myemail, $subject, $message);
/* Redirect visitors to the thank you page */
header('Location: ../thanks.html');
function show_error($myError)
{?>
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
什麼是「表單的一部分」,您期望看到什麼。 – AD7six 2013-02-13 22:21:21
你能準確的告訴我們哪個部分不起作用嗎?電子郵件是否完全發送?網頁上的任何錯誤?等等也emailaddress驗證:[你做錯了](http://stackoverflow.com/questions/12026842/how-to-validate-an-email-address-in-php/12026863#12026863)。 – PeeHaa 2013-02-13 22:27:02
使用以下內容過濾電子郵件:filter_var($ email,FILTER_VALIDATE_EMAIL)至於問題是什麼部分顯示不正確? – Steven10172 2013-02-13 22:28:47