我正在測試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
我無法描繪出這樣做的原因。
請幫我解決這個問題。
感謝
潘卡
代碼看起來不錯 - 它必須是sendmail本身的問題。嘗試從另一種方式或查看MTA日誌(如果您有shell訪問權限)。 – trojanfoe 2011-02-07 08:13:24
閱讀`/ var/log/maillog`。一個成功的`mail`調用只是意味着郵件被移交給`sendmail`,而不是`sendmail`實際上將它從服務器上卸下。 – 2011-02-07 08:13:59