我有一個簡單的電子郵件形式的PHP文件,我嘗試發送電子郵件,但似乎我的變量爲空。我的代碼後面有一個回顯,用於測試我的變量是否有任何值,並且它們不是打印的。唯一打印的是'完成'和'email $ to'。我做錯了什麼?我在YouTube上發佈了一個帖子,他採用了這種方法,他做了完全相同的事情,併爲他工作。我也嘗試了更多的電子郵件PHP文件,但仍然沒有。 這是我的html和php代碼。在PHP電子郵件形式的空變量
PHP代碼:
<?php
$name = $_REQUEST['author'];
$from = $_REQUEST['email'];
$subj = $_REQUEST['sub'];
$message = $_REQUEST['msg'];
$headers .= "From: ".$from;
$to = "[email protected]";
$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>
問題是否解決? – Joddy
現在我得到的價值。但我在if語句中出錯。它發展我的if語句的其他部分:/ – lantonis
嘗試PEAR郵件包發送郵件 – Joddy