IM currnetly製作一個網站和IM添加信息PHP的電子郵件卡住我有一個表格JavaScript驗證使用領域
<form name="inputForm" onSubmit="return validateForm();" action="#">
<fieldset>
<p>
<label>First Name:</label>
<input type="text" name="first_name"/><br />
<label>Surname:</label>
<input type="text" name="surname"/><br />
<label>Address number:</label>
<input type="text" name="address_number"/><br />
<label>Address name:</label>
<input type="text" name="address_name"/><br />
<label>Suburb:</label>
<input type="text" name="suburb"/><br />
<label>Postcode:</label>
<input type="text" name="postcode"/><br />
<label>State:</label>
<select name="state">
<option value="nsw">NSW
<option value="qld">QLD
<option value="act">ACT
<option value="vic">VIC
<option value="sa">SA
<option value="tas">TAS
<option value="nt">NT
<option value="wa">WA
</SELECT><br />
<label>Email:</label>
<input type="text" name="email"/><br />
<label>Phone Number:</label>
<input type="text" name="phone"/><br />
<input type="submit" name="submit" value="Send form" />
<input type="reset" name="reset" value="reset" />
</p>
</fieldset>
</form>
,然後由JavaScript
function validateForm()
{
var form = document.forms['inputForm'];
var formats =
{
first_name: /^[a-zA-Z]+[\-'\s]?[a-zA-Z]+$/, /*works for a-Z allows - and '*/
surname: /^[a-zA-Z]+[\-'\s]?[a-zA-z]+$/, /*works for a-Z allows - and '*/
postcode: /^\d{4}$/, /*4digit post code australia wide*/
email: /^\w+([\.-]w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/, /*allows all word characters and normal email formats*/
address_number: /^\d[0-9]$/, /*allows any number of digits*/
address_name: /^\w?\s?[a-zA-Z]+(,?\s([a-zA-Z])*)*$/, /*allows numbers space capital letters and other word characters*/
suburb: /^\w?\s?[a-zA-Z]+(,?\s([a-zA-Z])*)*$/, /*allows numbers space capital letters and other word characters*/
phone: /^\d{8}$/, /*8 number phone number*/
};
var elCount = form.elements.length;
for(var i = 0; i<elCount; i++)
{
var field = form.elements[i];
if(field.type == 'text')
{
if(!formats[field.name].test(field.value))
{
alert('invalid '+ field.name.replace('_',' ')+'.'); /*alerts the name of the area not filled right in a pop up box*/
field.focus();
return false;
}
}
}
alert('All fields correct, the form will now submit.')
}
然後我需要的PHP收集驗證該信息並將其發送到我的電子郵件地址(這是我卡住的地方)
<?php
if(isset($_POST['submit']) || isset($_POST['submit_x']))
{
$to = "[email protected]";
$subject = 'subject';
$message = 'testing the php mail() function';
$headers = "from: email\r\n";
$body="
Name: $name\n
Email: $email\n
";
echo "the information has been sent we will be in contact with you shortly";
mail($to, $subject, $message, $headers);
}
else
{
echo "The informations has not been sent";
}
?>
現在我b EEN抓我的頭在這幾天看着它無法找到任何東西我還在學習PHP和JavaScript
的JavaScript和HTML做工精細它只是短信功能,請幫助
什麼問題?請問一個問題。 – Bergi 2012-04-10 07:04:19
檢查您的服務器是否可以使用mail()函數。如果允許,請驗證您是否支持該功能。 – Lobo 2012-04-10 07:05:41
嘗試在沒有任何依賴的情況下調用郵件函數,只需使用普通的PHP腳本即可。我想這也可能不起作用,因爲你沒有[設置](http://www.php.net/manual/en/mail.setup.php)郵件正確。 – fragmentedreality 2012-04-10 07:07:56