我有一個需要姓名,電話和和可選註釋部分的註冊表單。運行多個測試後,表單似乎提交併且(php代碼的底部)頁面將我重定向到「謝謝你的頁面」。但我沒有收到任何電子郵件。任何人都知道我在做什麼錯了?我的HTML表單提交但我沒有收到電子郵件
<form class="register-form" name="registerform" method="post" action="form-to-email.php">
<div class="form-column">
<p>Fields marked with * are required.</p>
<label for="first_name">First Name *</label>
<input type="text" id="first_name" name="first_name" placeholder="John">
<label for="last_name">Last Name *</label>
<input type="text" id="last_name" name="last_name" placeholder="Smith">
<label for="phone">Phone Number</label>
<input type="text" id="phone" name="phone" placeholder="503 999 9999">
<label for="comments">Comments</label>
<textarea id="comments" name="comments"></textarea>
</div><!--/ Form Column -->
<div class="submit-wrap"><input class="submit-form" type="submit" value="Register" /></div>
</form><!--/ Form -->
的PHP是這樣的:?
<?php
$myemail = '[email protected]';
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$visitor_phone = $_POST['phone'];
$comments = $_POST['comments'];
$to = $myemail;
$email_subject = "$first_name\n $last_name\n registered for Winter Camp 2015";
$email_body = "They said: \n $comments". "Their phone number is $visitor_phone.\n".
$headers = "From: $myemail\n";
mail($to,$email_subject,$email_body,$headers);
header('Location: registered-thanks.html');
>
您的服務器是如何設置的?您的服務器上是否安裝了所需的位(即MTA等)並能夠中繼郵件? – slugonamission 2014-12-18 23:05:22
你的代碼有錯誤。 '$ email_body ='不以分號結尾。 – RST 2014-12-18 23:10:32