简体   繁体   English

从Windows服务器发送PHP邮件

[英]Sending PHP mail from Windows server

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. 直到最近,表单都托管在Linux服务器上,我没有遇到任何问题 - 邮件已发送和接收。 Recently I had to move to shared Windows server and since the move the mail is not sent. 最近我不得不转移到共享Windows服务器,因为移动邮件没有发送。 Here's the code that supposed to send the mail: 这是应该发送邮件的代码:

function send_contact_form($strName, $strEmail, $strPhone, $strMessage)
{
$to = 'mymail@mysite.com';
$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);
}

In a windows environment PHP uses SMTP insted of the Linux binary sendmail (or replacement) 在Windows环境中,PHP使用Linux二进制sendmail(或替换)的SMTP

You need to edit php.ini according to this page to be able to send e-mail via the mail() function. 您需要根据此页面编辑php.ini才能通过mail()函数发送电子邮件。

On Linux, PHP uses an application called sendmail. 在Linux上,PHP使用名为sendmail的应用程序。 Of course there is no similar applicaion on Windows. 当然,Windows上没有类似的应用程序。 As php.ini file says, to be able to work with mail function, you need to setup mail server coordinates. 正如php.ini文件所说,为了能够使用邮件功能,您需要设置邮件服务器坐标。 If You don't have mail server, it is not possible to send emails from PHP. 如果您没有邮件服务器,则无法从PHP发送电子邮件。 Of course You could use some external server like gmail. 当然你可以使用像gmail这样的外部服务器。

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

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