我需要使用php脚本从我的linux服务器发送邮件。关于这个问题需要帮助,因为我是这个概念的新手。谢谢。
的index.php
<?php
require_once "Mail.php";
$from = " <onik@opsonin.net>";
$to = "<onik@opsonin.net>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://192.168.10.9";
$port = "25";
$username = "smtp_username";
$password = "smtp_password";
$headers = array
('From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory
('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail))
{
echo("<p>" . $mail->getMessage() . "</p>");
}
else {
echo("<p>Message successfully sent!</p>");
}
?>
答案 0 :(得分:-1)
如果您的代码正确,则可能是服务器配置问题。
使用以下简单步骤来配置 sendmail(对所有内容都回答“是”)
sudo apt-get install sendmail
sudo sendmailconfig
sudo service apache2 restart