Sending PHP mail from a Windows server

I have a form on my page. When the user clicks the "Submit" button, he must send an email with the data that he entered into the form. Until recently, the form was hosted on a Linux server, and I had no problems with it - mail was sent and received. I recently had to switch to a shared Windows server, and no mail has been sent since the move. Here is the code that should 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); } 
+4
source share
2 answers

On Windows, PHP uses SMTP built into the Linux sendmail (or replacement) binary

You need to edit php.ini according to on this page to send email through the mail () function.

+6
source

On Linux, PHP uses the sendmail application. Of course, there is no such application on Windows. As the php.ini file says, in order to work with the mail function, you need to configure the coordinates of the mail server. If you do not have a mail server, sending emails with PHP is not possible. Of course, you can use some kind of external server, for example gmail.

0
source

Source: https://habr.com/ru/post/1486490/


All Articles