PHP:SMTP和SMTP_PORT的运行时ini_set()的mail()函数在Linux上不起作用 [英] PHP: mail() function with runtime ini_set() for SMTP and SMTP_PORT not working on Linux

查看:296
本文介绍了PHP:SMTP和SMTP_PORT的运行时ini_set()的mail()函数在Linux上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用PHP代码通过SMTP HOST进行邮件发送,如下所示:

I have used a PHP code for Mailing using a SMTP HOST as given below:

        ini_set('SMTP','myserver');
ini_set('smtp_port',25);
$to = $email;
$headers  = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers  .= "From: NO-REPLY<no-reply@mydomain.com>" . "\r\n";
$subject = "Confirmation For Request";
$message = '<html>
                <body>
                    <p>Hi '.$firstname.' '.$lastname.'</p>
                    <p>
                        We recieved below details from you. Please use given Request/Ticket ID for future follow up:
                    </p>
                    <p>
                        Your Request/Ticket ID: <b>'.$ticketID.'</b>
                    </p>
                    <p>
                    Thanks,<br>
                    '.$team.' Team.
                    </p>
                </body>
            </html>';
mail( $to, $subject, $message, $headers ); 

现在,当我在Windows Localhost中执行代码时.我成功接收了邮件,但是,如果我在Linux设置上使用相同的代码,则我不会接收到任何邮件,尽管mail()函数在linux计算机中返回true也是...

Now When i execute the code in Windows Localhost.. I am succcesfully recieving the mail whereas, If I deply the same code on my Linux setup, I do not recieve anymail, though the mail() function returns true in linux machine as well....

在针对Windows localhost和Linux服务器的phpinfo进行调查时,对于邮件参数,我发现有一个不同之处,

On looking into the phpinfo for both windows localhost and Linux server, for mail parameters I found a single difference,

在Windows中,我发现sendmail_path =="No Value",而在linux服务器上,它显示为"usr/sbin/sendmail -t -i"

In Windows I found sendmail_path == "No Value", whereas on linux server it says, "usr/sbin/sendmail -t -i"

有人可以帮助我解决此问题吗?

Could some one help me to resolve this issue?

注意:在Windows中,它是WAMP设置,而Linux是专用服务器...

NOTE: In windows, its a WAMP setup, whereas Linux is a Dedicated server...

推荐答案

如果您查看的是php.ini,则有一个简短说明

If you're looking to your php.ini there is a short description that

ini_set('SMTP','myserver');
ini_set('smtp_port',25);

这两个值仅适用于Windows.因此,如果要在Linux上通过SMTP发送邮件,则必须安装例如postfix并构建中继.

This both values are only for Windows. So if you want to send mails over SMTP on linux you have to install postfix for example and build a relay.

https://www.linode.com/docs/email/postfix/postfix-smtp-debian7

或者实际上更容易使用的是一个可以通过套接字或Swiftmailer之类的curl发送SMTP邮件的库.

Or what is really much easier use a lib that can send SMTP mail over socket or curl like Swiftmailer.

http://swiftmailer.org/docs/sending.html

这很容易,而且可以正常工作.

Thats much easier and its working.

这篇关于PHP:SMTP和SMTP_PORT的运行时ini_set()的mail()函数在Linux上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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