我試圖做一個申請表,但它不會工作。我一直在網站上尋找一些答案,但沒有運氣。 - 我嘗試了幾種不同的腳本。HTML和PHP郵件應用程序不發送
而且我認爲我使用幾乎相同的PHP腳本作爲我的聯繫表格,但只有$ mail,$ subject和$ message - 並且它工作得很好。
這裏是我的代碼:
<?php
/* Set e-mail recipient */
$myemail = "[email protected]";
/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], "Enter your name");
$email = check_input($_POST['email'], "Enter a subject");
$birthday = check_input($_POST['birthday']);
$cloths = check_input($_POST['cloths'], "Write your message");
$currentclub = check_input($_POST['currentclub'], "Klub");
$coachphone = check_input($_POST['coachphone'], "Indtast din træners telefonnummer");
$team = check_input($_POST['team'], "Indtast dit nuværende holds navn");
$message = check_input($_POST['message'], "Du mangler motiveret ansøgning");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$message = "
name: $name
E-mail: $email
Birthday: $birthday
Cloths: $cloths
Currentclub: $currentclub
Clubranking: $clubranking
Coachphone $coachphone
Clubhis: $clubhis
Team: $team
Attention: $attention
Message: $message
";
/* Send the message using mail() function */
mail($myemail, $name, $birthday, $cloths, $currentclub, $clubranking, $coachphone, $clubhis, $team, $attention, $message);
/* Redirect visitor to the thank you page */
header('Location: kontakt.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)
{
?>
<html>
<body>
<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>
</body>
</html>
<?php
exit();
}
?>
我的HTML代碼:
<form class="email" action="application.php" method="post">
<div id="ansøgninger">
<h4>Name</h4> <input type="text" name="name">
<h4>Email</h4> <input type="text" name="email">
<h4>fødselsdag</h4> <input type="text" name="birthday">
<h4>Tøjstørrelse</h4>
<select name="cloths" size="1">
<option value="XS" name="cloths">XS</option>>
<option value="S" name="cloths">S</option>>
<option value="M" name="cloths">M</option>>
<option value="L" name="cloths">L</option>>
<option value="XL" name="cloths">XL</option>>
</select>
<h4>Nuværende klub</h4> <input type="text" name="currentclub">
<h4>Hvilken række spiller klubben i?</h4>
<select name="priority" size="1">
<option value="Low">Low</option>
<option value="Normal">Normal</option>
<option value="High">High</option>
<option value="Emergency">Emergency</option>
</select>
<br />
<h4>Nuværende træners telefonnummer</h4> <input type="text" name="coachphone">
<h4>Klubhistorik</h4> <input type="text" name="clubhis">
<h4>udvalgt hold?</h4> <input type="text" name="team">
<h4>Ting vi skal være opmærksomme på?</h4> <input type="text" name="attention">
<h4>Type</h4>
<select name="type" size="1">
<option value="update">Website Update</option>
<option value="change">Information Change</option>
<option value="addition">Information Addition</option>
<option value="new">New Products</option>
</select>
<br />
<h4>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>
</div>
</div>
</div>
是否可以在服務器之前發送郵件? –