Sending PHP mail from Windows server

走远了吗. 提交于 2020-01-11 02:49:24

问题


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:

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);
}

回答1:


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

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




回答2:


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.



来源:https://stackoverflow.com/questions/17135829/sending-php-mail-from-windows-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!