2011-02-07 121 views
0

我正在測試Linux(vps)服務器上的電子郵件功能。 這是下面的代碼我使用:電子郵件功能不能在linux(vps)服務器上工作

<?php 
    // --- CONFIG PARAMETERS --- // 
    // 
    $email_recipient = "[email protected]"; 
    $email_sender = "Sender Name"; 
    $email_return_to = "[email protected]"; 
    $email_content_type = "text/html; charset=us-ascii"; 
    $email_client = "PHP/" . phpversion(); 
// 
// ------------------------- // 

// --- DEFINE HEADERS --- // 
// 
$email_header = "From: " . $email_sender . "\r\n"; 
$email_header .= "Reply-To: " . $email_return_to . "\r\n"; 
$email_header .= "Return-Path: " . $email_return_to . "\r\n"; 
$email_header .= "Content-type: " . $email_content_type . "\r\n"; 
$email_header .= "X-Mailer: " . $email_client . "\r\n"; 
// 
// ---------------------- // 

// --- SUBJECT AND CONTENTS --- // 
// 
$email_subject = "Test email subject"; 
$email_contents = "<html>"; 
$email_contents .= "<h2>Test Email</h2>"; 
$email_contents .= "<br><b>Sender: " . $email_sender; 
$email_contents .= "<br><b>Recipient: " . $email_recipient; 
$email_contents .= "</html>"; 
// 
// ---------------------------- // 

$email_result = mail($email_recipient, $email_subject, $email_contents, $email_header); 
if ($email_result) echo "Email has been sent!"; 
else echo "Email has failed!"; 
?> 

當我執行代碼所花費很長時間來處理,然後顯示電子郵件已發送。但是電子郵件絕不會傳送給收件人。 我已經通過檢查的phpinfo發送電子郵件路徑在php.ini文件()函數,它顯示:

sendmail_from no value no value 
sendmail_path /usr/sbin/sendmail -t -i /usr/sbin/sendmail -t -i 

我無法描繪出這樣做的原因。

請幫我解決這個問題。

感謝

潘卡

+0

代碼看起來不錯 - 它必須是sendmail本身的問題。嘗試從另一種方式或查看MTA日誌(如果您有shell訪問權限)。 – trojanfoe 2011-02-07 08:13:24

+0

閱讀`/ var/log/maillog`。一個成功的`mail`調用只是意味着郵件被移交給`sendmail`,而不是`sendmail`實際上將它從服務器上卸下。 – 2011-02-07 08:13:59

回答

0

使用一個實際的電子郵件地址爲$ EMAIL_SENDER;如果不工作,請在郵件()函數[email protected](無論發件人的電子郵件是什麼)中寫入第5個參數

0

您是否嘗試過發送不同的收件人?你檢查了垃圾郵件嗎?我建議使用PHPMailer,它會照顧標題等,使生活更輕鬆。

0

確保您的sendmail服務正在運行,有時您需要爲您的VPS手動啓動它。它應該是這樣的:

 

/etc/init.d/sendmail start 
 
相關問題