PHP:用于 SMTP 和 SMTP_PORT 的带有运行时 ini_set() 的 mail() 函数在 Linux 上不起作用

Pad*_*ter 6 php sendmail ini-set

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

        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 ); 
Run Code Online (Sandbox Code Playgroud)

现在,当我在 Windows Localhost 中执行代码时.. 我成功地收到了邮件,而如果我在 Linux 设置上发送相同的代码,我不会收到任何邮件,尽管 mail() 函数在 linux 机器中也返回 true。 ...

在查看 windows localhost 和 Linux 服务器的 phpinfo 时,对于邮件参数,我发现了一个区别,

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

有人可以帮我解决这个问题吗?

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

小智 0

我之前已经看过这个,在 PHP.ini 中有两个键sendmail_from http://php.net/sendmail-from(对于 Win32)和sendmail_path http://php.net/sendmail-path(对于 Unix) wamp 或类似的 Linux 设置,该键的默认值是 me@localhost,当在实际的邮件服务器上时,它应该拒绝该电子邮件地址作为用户,因为它们在服务器上不存在。

尝试添加类似...

ini_set('sendmail_from','admin@example.co.uk')
Run Code Online (Sandbox Code Playgroud)