我正在尝试使我的电子邮件表单正常工作,但它没有。我找到了一个现成的fromtoemail.php
文件,并用我的替换了变量。我尝试了一些我发现的在线代码,但每个人都给了我同样的错误。我收到错误,它跟踪的第一个字段发现它为空,我从我的代码中收到错误消息,而不是在所有循环中移动。我在第一行用 if 得到错误
if($author == '') {print "You have not entered an author, please go back and try again";}
这是来自 php 和来自我的 html 的代码。
PHP:
<?php
$to = $_REQUEST['myemail@gmail.com'] ;
$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 webmaster@YourCompany.com"; }
}
}
}
?>
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>