php pear电子邮件与gmail smtp配合使用,但不会通过本地服务器发送电子邮件
我刚刚升级到ubuntu 12.04,安装了pear、mail和mail_mime。我正在使用下面的示例代码。它过去可以工作,但我不确定是否在php.ini中做了一些更改。从上次安装到现在已经有一段时间了。我用gmail smtp服务器进行了测试,一切正常php pear电子邮件与gmail smtp配合使用,但不会通过本地服务器发送电子邮件,php,email,pear,Php,Email,Pear,我刚刚升级到ubuntu 12.04,安装了pear、mail和mail_mime。我正在使用下面的示例代码。它过去可以工作,但我不确定是否在php.ini中做了一些更改。从上次安装到现在已经有一段时间了。我用gmail smtp服务器进行了测试,一切正常 <? include('Mail.php'); include('Mail/mime.php'); // Constructing the email $sender =
<?
include('Mail.php');
include('Mail/mime.php');
// Constructing the email
$sender = "Leigh <leigh@no_spam.net>"; // Your name and email address
$recipient = "Leigh <leigh@no_spam.net>"; // The Recipients name and email address
$subject = "Test Email"; // Subject for the email
$text = 'This is a text message.'; // Text version of the email
$html = '<html><body><p>This is a html message</p></body></html>'; // HTML version of the email
$crlf = "\n";
$headers = array(
'From' => $sender,
'Return-Path' => $sender,
'Subject' => $subject
);
// Creating the Mime message
$mime = new Mail_mime($crlf);
// Setting the body of the email
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers);
// Sending the email
$mail =& Mail::factory('mail');
$mail->send($recipient, $headers, $body);
?>
我有什么遗漏吗?我应该更改php.ini中的sendmail_路径吗?还是什么?您可以从error.log文件中找到您的错误 apachecheck的应用
sudo tail -f /var/log/apapche2/error.log
在这里你可以找到你发送邮件的错误
sudo apt-get install php-pear
sudo pear install mail
sudo pear install Net_SMTP
sudo pear install Auth_SASL
sudo pear install mail_mime
任何尝试立即发送邮件的人:)您是否可以使用设置发送电子邮件?打开终端并键入:
mailyour@emailaddre.ss[enter]test[enter]test[enter][enter]ctrl+d
并检查您的电子邮件。@John我试过了,但它说没有安装mailutils。但即使在尝试安装它之前,我就知道php并没有附带sendmail默认值,所以我必须安装它。我安装了它,现在它发送邮件(虽然需要10-15秒),谢谢你的回复。错误日志中没有任何内容。除了Auth_SASL之外,我已经安装了所有软件,但都无法正常工作。之后我安装了sendmail,现在它发送邮件,但速度非常慢。知道为什么要花这么长时间吗?在我之前的安装中,我曾经让它工作得很好