2016-12-16 37 views
0

使用電子郵件功能提交表單:任何人都可以告訴我什麼是我的郵件表單錯誤,雖然數據正確發佈但電子郵件沒有發送。爲什麼?

$to = "[email protected]***.com"; 
$from = $_REQUEST['email']; 
$name = $_REQUEST['name']; 
$phone = $_REQUEST['phone']; 
$message = $_REQUEST['message']; 

$subject = "Form submission"; 

$message = $name . " " . $phone . " " .$message. " wrote the following:" . "\n\n" . $_REQUEST['message']; 

$headers = "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=isoo-8859-1\r\n"; 
$headers = "From:" . $from; 

我不能夠發送電子郵件

mail($to,$subject,$message,$headers); 

header('Location: thank-you.php'); 
+1

mail()函數並不總是足以在所有託管提供程序中發送郵件。嘗試SMTP或PHPMailer。 – Bhavin

+0

並使用'$ _POST'而不是'$ _REQUEST'。請求包含GET,POST和COOKIE,所以您不能確定數據是否來自帖子。 – Twinfriends

回答

2

你的最後一個頭被打破了。

$headers = "From:" . $from; 

它也需要點(連接)。

$headers .= "From:" . $from; 

郵件被拒絕,因爲沒有有效From和由它被打破而引起的。

相關問題