2013-11-21 56 views
0

我試圖做一個申請表,但它不會工作。我一直在網站上尋找一些答案,但沒有運氣。 - 我嘗試了幾種不同的腳本。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> 
+0

是否可以在服務器之前發送郵件? –

回答

1

基本mail()函數有3個參數,像這樣

mail(to, subject, message) 

您可以添加標題和其他參數太。

mail()線改爲

mail($myemail, $email, $message); 
+0

非常感謝。有效。 – user3017725

2

你沒有正確調用mail

mail($myemail, $name, $birthday, $cloths, $currentclub, $clubranking, $coachphone, $clubhis, $team, $attention, $message); 

的手冊頁是在這裏:http://php.net/manual/en/function.mail.php - 你需要的電子郵件地址通過;主題行;和消息;有幾個可選參數。您需要連接所有文字到一個消息變量,傳遞變量,而不是每個不同的值:

mail ($myemail, 'Subject', $message); 
0

您閱讀郵件功能的文檔, http://php.net/manual/en/function.mail.php

mail($myemail, $name, $birthday, $cloths, $currentclub, $clubranking, $coachphone, $clubhis, $team, $attention, $message); 

要傳遞的mail()函數參數是錯誤的...

你嘗試寫 mail($myemail, $email, $message)

變量$myemail應該存儲收件人的電子郵件和$email應該有存儲在其中的主題,$消息應該包含您要發送的消息。

0

我相信錯誤看起來是在使用你的郵件()的PHP函數,這個函數只需要最多5個參數

mail($myemail, $name, $birthday, $cloths, $currentclub, $clubranking, $coachphone, $clubhis, $team, $attention, $message); 

你似乎已經包括$名稱,$生日,$布料,$ currentclub,$ clubranking,$ coachphone,$ clubhis,$ team,$ attention,$ message已經存在於你的$ message變量中,所以不需要再在郵件函數中包含這些。

您的代碼應類似於:

$emailMessage = " 
name: $name 
E-mail: $email 
Birthday: $birthday 
Cloths: $cloths 
Currentclub: $currentclub 
Clubranking: $clubranking 
Coachphone $coachphone 
Clubhis: $clubhis 
Team: $team 
Attention: $attention 
Message: $message 
"; 

mail($myemail, $subject, $emailMessage); 

參考http://php.net/manual/en/function.mail.php的郵件()函數的用法。

0

請參閱郵件示例代碼.. https://stackoverflow.com/questions/20072751/write-the-email-code-for-upload-resume-in-contact-page-receive-the-email-in-php/20073275#20073275

發送一個簡單的電子郵件:

<?php 
$txt = "First line of text\nSecond line of text"; 

// Use wordwrap() if lines are longer than 70 characters 
$txt = wordwrap($txt,70); 

// Send email 
mail("[email protected]","My subject",$txt); 
?> 

發送電子郵件與額外的頭:

<?php 
$to = "[email protected]"; 
$subject = "My subject"; 
$txt = "Hello world!"; 
$headers = "From: [email protected]" . "\r\n" . 
"CC: [email protected]"; 

mail($to,$subject,$txt,$headers); 
?> 

發送HTML電子郵件:

<?php 
$to = "[email protected], [email protected]"; 
$subject = "HTML email"; 

$message = " 
<html> 
<head> 
<title>HTML email</title> 
</head> 
<body> 
<p>This email contains HTML Tags!</p> 
<table> 
<tr> 
<th>Firstname</th> 
<th>Lastname</th> 
</tr> 
<tr> 
<td>John</td> 
<td>Doe</td> 
</tr> 
</table> 
</body> 
</html> 
"; 

// Always set content-type when sending HTML email 
$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; 

// More headers 
$headers .= 'From: <[email protected]>' . "\r\n"; 
$headers .= 'Cc: [email protected]' . "\r\n"; 

mail($to,$subject,$message,$headers); 
?>