March 12, 2012
Email Sending from Local Server in PHP
Question by Samir
I have my file mail.php :
<html>
<body>
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail("syedsamiruddin29@gmail.com", $subject,
$message, "From:" . $email);
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='mail.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?>
</body>
</html>
but when i run it. i get this error :
Warning: mail() [function.mail]: Failed to connect to mailserver at "127.0.0.1" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:Program FilesEasyPHP-5.3.8.1wwwsafepay247mail.php on line 13
Thank you for using our mail form
what im trying to do is to send an email to my email id : syedsamiruddin29@gmail.com using php to the person’s email written in the input type.
Ive gone through many videos but none help me solve the php.ini problem.
Answer by Starx
Its not that complicated
-
Open the
php.ini
. -
Search for the attribute called
SMTP
in the php.ini file. Generally you can find the lineSMTP=localhost
. change the localhost to the smtp server name of your ISP. And the set the port of 25.SMTP = smtp.gmail.com #user your smtp address here smtp_port = 25
-
Restart the apache server or wamp or xammp. Whatever you are using.
-
Now try to send the mail using the mail() function