Search code examples
phpxampp

How to send emails from local host?


I made a webpage to send emails and I am using XAMPP as local host. While I am receiving this warning:

Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\sendMessage\acknowledge.php on line 12

Here is my code. line 12 is marked:

<?php
$headers = "";
if (isset($_POST['email'])){
    $to = 'anthonylaw8910@gmail.com';
    $subject = 'message from site';
    }
$message = 'Name: '.$_POST['name']."\r\n\r\n";
$message.= 'Email: '.$_POST['email']."\r\n\r\n";
$message.= 'Comments: '.$_POST['comments'];
$headers = "From: bakery@gmail.com\r\n";
$headers.= 'Content-Type: text/plain; charset=utf-8';
//check line 12 below:
$success = mail($to, $subject, $message, $headers);
?>

This is just a practice for myself and I do not have a server. How do I make it work in this circumstance?

Thanks a lot for your help.


Solution

  • You need to be running a mail server locally. If this is Unix, enable sendmail If this is Windows install the Simple Mail Transfer Server (not sure if the name is correct) component of IIs. E.g. for windows 2003 follow this: http://msdn.microsoft.com/en-us/library/8b83ac7t.aspx