我正在测试linux(vps)服务器上的电子邮件功能。 这是我正在使用的以下代码:
<?php
// --- CONFIG PARAMETERS --- //
//
$email_recipient = "recipient@demo.com";
$email_sender = "Sender Name";
$email_return_to = "sender@demo.com";
$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
我无法找出原因。
请帮我解决这个问题。
由于
的Pankaj
答案 0 :(得分:0)
使用实际的电子邮件地址作为$ email_sender;如果不工作,请在mail()函数-fsenderemail@mail.com中写入第5个参数(无论发件人的电子邮件是什么)
答案 1 :(得分:0)
您是否尝试过发送不同的收件人?你检查过spambox吗?我建议使用PHPMailer,它会处理标题等,使生活更轻松。
答案 2 :(得分:0)
确保您的sendmail服务正在运行,有时您需要手动为您的VPS启动它。它应该是这样的:
/etc/init.d/sendmail start