在我的HTML頁面中,我創建了一個響應表單。 該操作是將te值發送到PHP文件。這個PHP文件必須照顧發送電子郵件。當在字段中輸入值並按下提交按鈕時,我會得到我的「成功」頁面(並且,當我填寫錯誤時,出現錯誤頁面)。所以這部分似乎工作正常。PHP郵件不發送電子郵件
我已經在我的Mac上安裝了MAMP作爲PHP服務器。在php.ini文件中,sendmail的路徑設置爲/usr/sbin/sendmail -t -i
據我所知,這是正確的。但是,不發送郵件。
有什麼建議嗎?請指教。
請參閱下面的互聯網上找到,並改變了代碼:
<?php
/*
This first bit sets the email address that you want the form to be submitted to.
You will need to change this value to a valid email address that you can access.
*/
$webmaster_email = "[email protected]";
/*
This bit sets the URLs of the supporting pages.
If you change the names of any of the pages, you will need to change the values here.
*/
$feedback_page = "contact.html";
$error_page = "error_message.html";
$thankyou_page = "thank_you.html";
/*
This next bit loads the form field data into variables.
If you add a form field, you will need to add it here.
*/
$naam = $_REQUEST['naam'];
$email = $_REQUEST['email'] ;
$telefoon = $_REQUEST['telefoon'];
$website = $_REQUEST['website'];
$opmerkingen = $_REQUEST['opmerkingen'] ;
/*
The following function checks for email injection.
Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
*/
function isInjected($str) {
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}
}
// If the user tries to access this script directly, redirect them to the feedback form,
if (!isset($_REQUEST['email'])) {
header("Location: $feedback_page");
}
// If the form fields are empty, redirect to the error page.
elseif (empty($naam) || empty($email) || empty($opmerkingen)) {
header("Location: $error_page");
}
// If email injection is detected, redirect to the error page.
elseif (isInjected($email_address)) {
header("Location: $error_page");
}
// If we passed all previous tests, send the email then redirect to the thank you page.
else {
mail("$webmaster_email", "Contactformulier van OpenWater",
$comments, "From: $email");
header("Location: $thankyou_page");
}
?>
請發佈您用來發送郵件的代碼。 – 2013-04-23 12:32:30
@Jamie,謝謝你的支持。只需添加php代碼。 – A3O 2013-04-23 12:40:33
正如其他人所提到的,也許你應該首先檢查一下PHP能否以最簡單的形式發送郵件。我不認爲它比這更簡單:'<?php var_dump(mail('[email protected]','test','test')); ?>'。你看到了什麼? – 2013-04-23 13:15:45