Asked By
johnyy
0 points
N/A
Posted on - 10/01/2011
Hello everybody,
I am new to PHP (self study) and i would like some help with mail() function.
I keep getting an error that i don't understand, and i am pretty sure i do it exactly as the book says with no syntax error or logical error. So please help me to fix this issue.
I uploaded an image of my code and the error.
Thanks for your help. 😀
Answered By
schild
5 points
N/A
#84564
PHP error with mail() function on xamp
See the warning on your image, it said that your mail() function failed to connect to smtp_server, then you must set up your smtp server before you can send email through xampp. And you must make sure you have ISP to send email. You can get it by purchasing cheap hosting test send your phpmail. After you have your server, go to smtp setup in cpanel, and note down your server smtp setting.
Look for php.ini in explorer, usually on folder xampphtdocsphp. Then find SMTP=localhost.
Change “localhost” with your isp/host smtp port, like smtp.yourisp.com and port in 25. Save it then restart xampp. Now try send your email with your mail() function again.
You can find get some ideas here.
PHP error with mail() function on xamp
Hi there Johnyy,
I am also a newbie in PHP. I tested your mail script and it worked perfectly fine. It actually sent the message to my gmail account. Here are the steps that I used:
1. Be sure you have internet connection.
2. Visit cPanel Store.
3. Try to sign-up and register using your email for this test phase.
4. Once you got your free sub-domain (example mine was chie.site90.com) you can use your C panel to go to File manager and upload files.
5. If you are now at the File Manager you can use upload feature to upload the following files:
phpinfo.php ( I use this to check if the site is PHP compliant)
mail.php (This was your script)
6. Here are the codes:
phpinfo.php
<?php phpinfo() ?>
mail.php
<?php
$subject=’Hello’;
$body=’Would you like to join us?’;
mail($to,$subject,$body,’From!’.$from);
?>
7. You can then test by typing the URL
http://error404.000webhost.com/?
Hope this can help.
PHP error with mail() function on xamp
Hi,
Run this script on your localhost.
Mailform.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("[email protected]", $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='mailform.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>