Sending e-mail from localhost in PHP in Windows Environment

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Sending e-mail from localhost in PHP in Windows Environment

Postby aj123cd » 08. August 2009 09:29

Sending e-mail from localhost in PHP in Windows Environment
Have you ever been frustrating, why e-mail is not going from the localhost while using XAMPP or WAMP or any other PHP servers in windows environment?
1. Open the php.ini
2. Search for the attribute called “SMTP” in the php. find the line “SMTP=localhost“. Change the localhost to the SMTP server name of your ISP. And, there is another attribute called “smtp_port” which should be set to 25.I’ve set the following values in my php.ini file.
smtp_port = 25
3. Restart the apache server so that PHP modules and attributes will be reloaded.
4. Now try to send the mail using the mail() function,
mail(””,”test subject”,”test body”);
You might get the warning like this,
Warning: mail() [function.mail]: “sendmail_from” not set in php.ini or custom “From:” header missing in C:\Program Files\xampp\htdocs\testmail.php on line 1
5. Now specify the following headers and try to send the mail again,
$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers.= "From: $from\r\n";
Some smtp server verifies the email address of the sender so the email address which is in the place of “” should be a valid and existing email address otherwise mail might not be sent to the “”.
SMTP server, just call your ISP (internet service provider) and ask for the SMTP host name and you cannot do it without internet connection.
Full PHP code.
$to="Recipient Name <>";
$from="Sender Name <>";
$subject="My first HTML E-mail";
$message="<h1>HTML E-mail</h1>
<p>This is an <b>HTML</b> e-mail.</p>";
$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers.= "From: $from\r\n";
if (mail($to, $subject, $message, $headers))
echo "Message Sent!";
echo "Failed to send message.";
Posts: 62
Joined: 03. June 2009 08:19
Location: London,UK

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 50 guests