我在 php 文件中有一个简单的电子邮件表单,我尝试发送电子邮件,但似乎我的变量为空。在我的代码之后我有一个回显,只是为了测试我的变量内部是否有任何值并且它们没有被打印出来。唯一打印的是“done”和“email $to”。我做错什么了吗?我从 youtube 上的帖子中遵循了这种方法,他做了完全相同的事情,并且对他有用。我还尝试了更多电子邮件 php 文件,但仍然没有。这是我的html和php代码。
php代码:
<?php
$name = $_REQUEST['author'];
$from = $_REQUEST['email'];
$subj = $_REQUEST['sub'];
$message = $_REQUEST['msg'];
$headers .= "From: ".$from;
$to = "mygmail@gmail.com";
$subject = $subj;
$body = $message;
if(mail($to,$subject,$body,$headers)) {
echo "An e-mail was sent to ".$to." with the subject: ".$subject;
} else {
echo "There was a problem sending the mail. Check your code and make sure that the e-mail address ".$to." is valid";
}
?>
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="sub" id="sub" class="input_field" />
</p>
<div class="cleaner h20"></div>
<label for="text">Message:</label>
<textarea id="msg" name="msg" 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>