2013-07-18 85 views
0

我有一個網站的表單是假設發送電子郵件給我的公司和另一個填寫表格的用戶。我已經將網站的所有附加文件加載到服務器,但是當我填寫表單以測試它時,彈出一個錯誤,提示「未找到」。我正在使用PHP的GET方法來處理它。我是PHP新手,一般都是網頁設計。謝謝。PHP腳本沒有發送/接收電子郵件

<?php 
//Function that sends the email to the person who submitted the form 
function send_email(){ 
//This sends an email to the person who submitted the form 
// email fields: to, from, subject. Put your values here! 
$sendermail = '[email protected]'; 
$from = "Company<".$sendermail.">"; 
$to = $_GET['email']; 
$subject = 'Product Information'; 
$message = "A member of our sales team will be getting back to you shortly. Thank you for your interest in our great line of products."."\n\n"."Best Regards,"."\n\n"."The Team"; 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/plain; charset=iso-8859-1' . "\n"; 
$headers .= 'From: '. $from . "\r\n" . 
'Reply-To: '. $sendermail. "\r\n" . 
'X-Mailer: PHP/' . phpversion(); 

$ok = @mail($to, $subject, $message, $headers); 

//This sends the contents of the form submission to the website owner 
$sendermail2 = $_GET['email']; 
$from2 = $_GET['first-name'].' '.$_GET['last-name'].' <'.$sendermail2.'>'; 
$to2 = '[email protected]'; 
$subject2 = 'A customer submission from the product page'; 
$message2 = "Name: ". $_GET['first-name'] ." ". $_GET['last-name'] ."\n\n". "Company: ". $_GET['company'] ."\n\n". "Email: ". $_GET['first-name'] ."\n\n". "Interest: ".$_GET['Interest']; 
$headers2 = 'MIME-Version: 1.0' . "\r\n"; 
$headers2 .= 'Content-type: text/plain; charset=iso-8859-1' . "\n"; 
$headers2 .= 'From: '. $from2 . "\r\n" . 
'Reply-To: '. $sendermail2. "\r\n" . 
'X-Mailer: PHP/' . phpversion(); 

$ok2 = @mail($to2, $subject2, $message2, $headers2); 
} 
return send_email(); 
?> 

...這段代碼在HTML頁面的主體中。

<FORM ACTION="http://www.server.com/html/form_process.php" METHOD=GET> 
+0

你運行什麼郵件服務器? – 3ventic

+0

Apache/2.0.52(紅帽)服務器 – Jeremiah

+0

Apache是​​網絡服務器。你運行什麼郵件服務器? PHP郵件功能並不神奇地發送電子郵件,它與例如Postfix的SMTP服務器掛鉤。 –

回答

0

解決方案紅帽服務器:

sudo yum install postfix 

隨後:

sudo echo "sendmail_from = [email protected]" >> /your/directory/php.ini 

最後:

sudo echo "sendmail_path = /usr/sbin/sendmail -t -i -f [email protected]" >> /your/directory/php.ini 

替換/your/directory/php.ini與你的真正的php.ini目錄和[email protected]與你想要的電子郵件地址,並重新啓動apache,php和postfix,或直接服務器。

+0

我很難理解這個答案。我確定這是我而不是你。從初學者的角度來看,是否有可能獲得更容易理解的解釋?謝謝。 – Jeremiah

+0

是的,您只需通過SSH連接到服務器(您可以使用PuTTY)並運行我寫的命令。 – user2584820

0

未找到錯誤通常意味着您要將表單發送到錯誤的URL。檢查你要發送到的URL和php文件的路徑,看看它們是否正確

+0

該URL與路徑的關係如何。所以我很確定不是這樣。 – Jeremiah