我有這段代碼。它打印「郵件發送成功」,但我的郵箱裏沒有來自我的測試的消息。php - 發送電子郵件不工作
下面是HTML代碼:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Basic Email Form</title>
<style>
* {
margin:0;
padding:0;
}
input, textarea {
margin:10px;
font-family:Arial, sans-serif;
padding:10px;
}
input {
width:280px;
height:40px;
}
textarea {
width:280px;
height:120px;
}
</style>
</head>
<body>
<form action="submit.php" method="post">
<input type="text" name="name" placeholder="Name" /><br />
<input type="text" name="from" placeholder="Email" /><br />
<textarea placeholder="Message" name="message"></textarea><br />
<input type="submit" value="Submit" />
</form>
<body>
</html>
PHP文件:
<?php
$to = "[email protected]";
$subject = "This is subject";
$message = "This is simple text message.";
$header = "From:".$_POST['from']." \r\n";
$retval = mail ($to,$subject,$message,$header);
if($retval == true)
{
echo "Message sent successfully...";
}
else
{
echo "Message could not be sent...";
}
?>
可能去了垃圾文件夾? – tonoslfx
您最好檢查一下您的郵件服務器配置,因爲僅僅從mail()函數返回TRUE值並不能確保郵件已經到達目的地。 –
@ kalpeshpatel你打敗了我,嘿! – Majo0od