6

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);
}
Igal
  • 5,833
  • 20
  • 74
  • 132
  • 1
    Duplicate of http://stackoverflow.com/questions/5585445/php-mail-will-not-send-from-windows-server-2008?rq=1 – Fluff Jun 16 '13 at 17:23

2 Answers2

7

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.

Aakash Martand
  • 926
  • 1
  • 8
  • 21
Fluff
  • 548
  • 4
  • 8
  • I want to make sure I understood correctly: do I have to edit the php.ini file only and don't have to alter my code above at all? Or do I still need to make some changes to it? – Igal Jun 16 '13 at 17:31
  • 1
    Correct you only need to edit php.ini and not your code. Under Windows PHP uses the setting SMTP = 'smtpserver' and let's the mail()-function send mail to that server. – Fluff Jun 16 '13 at 17:34
0

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.

Flash Thunder
  • 11,672
  • 8
  • 47
  • 91