简体   繁体   English

php5 mail() function 发送邮件错误

[英]php5 mail() function sendmail error

I'm trying to use php's mail() function but keep getting an error.我正在尝试使用 php 的 mail() function 但不断收到错误消息。 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:我已经通过sudo apt-get install sendmail ,编辑了我的/etc/php5/cli/php.ini文件,在这些行中添加了以下文本:

 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

This is odd because I have tried the sendmail_path with -t and without -t but I keep getting the same error.这很奇怪,因为我尝试了带 -t 和不带 -t 的 sendmail_path,但我一直收到同样的错误。 What am I doing wrong?我究竟做错了什么?

UPDATE: this is what my phpinfo() shows.更新:这是我的 phpinfo() 显示的内容。 (I added -t back but the command isn't working with or without it). (我添加了 -t ,但无论有没有它,该命令都不起作用)。

在此处输入图像描述

Another UPDATE -另一个更新 -

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..).我注释掉了 sendmail_path 和 sendmail_from 行,从头开始期望 mail() function 抱怨 php 不知道它是什么,但是我得到了与以前完全相同的错误(即使完全没有这两行..)。 This leads me to believe that it doesn't have to do with the sendmail program or mail() function at all...这让我相信它根本与 sendmail 程序或 mail() function 无关......

I don't know, but you might try sendmail_path = /usr/sbin/sendmail -t -i .我不知道,但您可以尝试sendmail_path = /usr/sbin/sendmail -t -i It's set so on webhosting which I use.它设置在我使用的虚拟主机上。 Otherwise, you might want to check if phpinfo() contains correct settings for sendmail .否则,您可能需要检查phpinfo()是否包含正确的sendmail设置。

I take the error to indicate that you are missing the information that -t would be looking for, 'To:', 'CC:', or 'BCC:'我认为该错误表明您缺少 -t 将要查找的信息“收件人:”、“抄送:”或“密件抄送:”

Try adding some extra info to your mail command line and see if that works:尝试在您的邮件命令行中添加一些额外的信息,看看是否有效:

php -r "mail('sadmicrowave@gmail.com', 'test subject', 'test body message', 'To: Receiver <receiver@email.com>');"

Look at the following sections in your phpinfo() output to make sure you're editing the correct file:查看 phpinfo() output 中的以下部分,以确保您正在编辑正确的文件:

  • Loaded Configuration File加载的配置文件
  • Additional.ini files parsed已解析的附加 .ini 文件

If the file you edited is not listed in one of those sections, the changes will have no effect.如果您编辑的文件未在这些部分之一中列出,则更改将无效。

I solved my issue by utilising the SwiftMailer module where I can specify a mailserver to relay through.我通过使用 SwiftMailer 模块解决了我的问题,我可以在其中指定一个邮件服务器进行中继。 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 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM