我正在测试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