php5 mail()函数sendmail错误 [英] php5 mail() function sendmail error

查看:26
本文介绍了php5 mail()函数sendmail错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 php 的 mail() 函数,但一直出现错误.我已经通过 sudo apt-get install sendmail 安装了 sendmail,编辑了我的 /etc/php5/cli/php.ini 文件,将以下文本添加到这些行中:>

I'm trying to use php's mail() function but keep getting an error. I've installed sendmail via sudo apt-get install sendmail, edited my /etc/php5/cli/php.ini file adding the following text to these lines:

 sendmail_path = /usr/sbin/sendmail -t
 sendmail_from = uslonsweb003.ALU@no-reply.com

然后我重新启动了我的网络服务器并使用此命令进行测试:

I then restarted my webserver and used this command for test:

 :~$ php -r "mail('sadmicrowave@gmail.com', 'test subject', 'test body message');"

但我每次都会收到以下错误!!!:

but I get the following error EVERYTIME!!!:

 sh: -t: not found

这很奇怪,因为我尝试了带 -t 和不带 -t 的 sendmail_path 但我一直收到同样的错误.我做错了什么?

This is odd because I have tried the sendmail_path with -t and without -t but I keep getting the same error. What am I doing wrong?

更新!这是我的 phpinfo() 显示的内容:(我添加了 -t 但该命令在使用或不使用它时都不起作用).

UPDATE! this is what my phpinfo() shows: (I added -t back but the command isn't working with or without it).

另一个更新 -

我注释掉了 sendmail_path 和 sendmail_from 行以从头开始期望 mail() 函数抱怨 php 不知道它是什么,但我得到了与以前完全相同的错误(即使完全没有这两行!!).这让我相信它根本与 sendmail 程序或 ma​​il() 函数无关...

I commented out the sendmail_path and sendmail_from lines to start from scratch expected the mail() function to complain that php doesn't know what it is but instead I get the EXACT same error as before (even without the two lines entirely!!). This leads me to believe that it doesn't have to do with the sendmail program or mail() function at all...

推荐答案

我通过使用 SwiftMailer 模块解决了我的问题,我可以在其中指定要中继的邮件服务器.我使用我公司的邮件服务器作为服务器属性并继续指定如下选项:

I solved my issue by utilising the SwiftMailer module where I can specify a mailserver to relay through. I used my company mailserver as the server property and continued specifying the options as follows:

require_once('/var/www/global/swiftmailer/lib/swift_required.php');
$transport = Swift_SmtpTransport::newInstance( 'mailout.usa.mycompany.com', 25 );
$mailer = Swift_Mailer::newInstance( $transport );
$message = Swift_Message::newInstance( 'Suggestion Status Update' )
    ->setFrom( array( 'uslonsweb003@no-reply.com' => 'SuggestionBox' ) )
    ->setTo( array( $pEmail => $username ) )
    ->setBody( $body, 'text/html' )
    ;
$result = $mailer->send( $message );

这篇关于php5 mail()函数sendmail错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆