我想讓我的電子郵件表格工作,但它沒有。我發現一個準備好的fromtoemail.php
文件,我用我的替換變量。我嘗試了一些我發現的在線代碼,但每個人都給我提供了同樣的錯誤。我得到錯誤,我的第一個字段,它跟蹤它發現它爲空,我從我的代碼中獲取錯誤消息,而不是全部遍歷所有的循環。我在這裏得到了錯誤的一號線與是否是在沒有打開電子郵件客戶端的PHP中的電子郵件表格
if($author == '') {print "You have not entered an author, please go back and try again";}
下面是從PHP代碼和HTML我。
PHP:
<?php
$to = $_REQUEST['[email protected]'] ;
$author = $_REQUEST['author'] ;
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$text = $_REQUEST['text'] ;
$headers = "From: $from";
$subject = "$subject";
$fields = array();
$fields{"author"} = "author";
$fields{"email"} = "email";
$fields{"subject"} = "subject";
$fields{"text"} = "text";
$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$headers2 = "$email";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com";
if($author == '') {print "You have not entered an author, please go back and try again";}
else {
if($email == '') {print "You have not entered a email, please go back and try again";}
else {
if($subject == '') {print "You have not entered a subject, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($email, $subject2, $autoreply, $headers2);
if($submit)
{header("Location: http://www.sofisarti.com/index-english.html");}
else
{print "We encountered an error sending your mail, please notify [email protected]"; }
}
}
}
?>
HTML:
<form action="formtoemail.php" method="post" enctype="text/plain">
<p>
<label for="author">Name:</label>
<input type="text" id="author" name="author" class="required input_field" />
</p>
<p>
<label for="email">Email:</label>
<input type="text" id="email" name="email" class="validate-email required input_field" />
</p>
<p class="no_margin_right">
<label for="subject">Subject:</label>
<input type="text" name="subject" id="subject" class="input_field" />
</p>
<div class="cleaner h20"></div>
<label for="text">Message:</label>
<textarea id="text" name="text" rows="0" cols="0" class="required"></textarea>
<div class="cleaner h20"></div>
<input type="submit" value="Send" id="submit" name="submit" class="submit_btn float_l" />
<input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_r" />
</form>
這是幹什麼的? $ fields {「author」} =「author」; –
將'var_dump($ _ REQUEST);'放在打開的PHP標記之後併發布輸出。 –
建議您將error_reporting(E_ALL)添加到腳本的頂部。可能會有一些依賴未定義的變量,這將引發關於這樣的事情的通知。 –