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

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

问题描述

我试图使用PHP的mail()函数,但不断收到错误。我通过命令和apt-get安装的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

这是奇怪,因为我曾尝试与sendmail_path -t和未使用-t,但我不断收到同样的错误。我在做什么错了?

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程序或邮件(做)函数在所有...

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天全站免登陆