从 Windows 服务器发送 PHP 邮件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17135829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:20:06  来源:igfitidea点击:

Sending PHP mail from Windows server

emailwindows-server-2008php

提问by Igal

I have a form on my page. When the user hits the Send button - it's supposed to send an email with the details he entered in the form. Up until recently the form was hosted on a Linux server and I had no problem with it - the mail was sent and received. Recently I had to move to shared Windows server and since the move the mail is not sent. Here's the code that supposed to send the mail:

我的页面上有一个表格。当用户点击发送按钮时 - 它应该发送一封电子邮件,其中包含他在表单中输入的详细信息。直到最近,该表单都托管在 Linux 服务器上,我对此没有任何问题 - 邮件已发送和接收。最近我不得不转移到共享的 Windows 服务器,并且由于转移邮件没有发送。这是应该发送邮件的代码:

function send_contact_form($strName, $strEmail, $strPhone, $strMessage)
{
$to = '[email protected]';
$subject = 'From the site';
$message =  '<html lang="HE">
            <head>
            <title>
                '.$subject.'
            </title>
            </head>
            <body style="text-align:right; direction:rtl; font-family: Arial;">
                Name: '.$strName.'<br>Email: '
                .$strEmail.'<br>Phone: '.$strPhone
                .'<br><br>Message: <br>'.$strMessage.'
            </body>
        </html>';       
$email = $strEmail;
$header  = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$header .= "From: $email\r\nReply-To: $email" . "\r\n";

mail($to, $subject, $message, $header);
}

回答by Fluff

In a windows environment PHP uses SMTP insted of the Linux binary sendmail (or replacement)

在 Windows 环境中 PHP 使用 SMTP 插入 Linux 二进制 sendmail(或替换)

You need to edit php.ini according to this pageto be able to send e-mail via the mail() function.

您需要根据此页面编辑 php.ini 才能通过 mail() 函数发送电子邮件。

回答by Flash Thunder

On Linux, PHP uses an application called sendmail. Of course there is no similar applicaion on Windows. As php.ini file says, to be able to work with mail function, you need to setup mail server coordinates. If You don't have mail server, it is not possible to send emails from PHP. Of course You could use some external server like gmail.

在 Linux 上,PHP 使用名为 sendmail 的应用程序。当然,Windows 上没有类似的应用程序。正如 php.ini 文件所说,为了能够使用邮件功能,您需要设置邮件服务器坐标。如果您没有邮件服务器,则无法从 PHP 发送电子邮件。当然,您可以使用一些外部服务器,例如 gmail。