PHP error with mail() function on xamp

Asked By 0 points N/A Posted on -

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. šŸ˜€


Best Answer by Bretty grey
Answered By 0 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 and port in 25. Save it then restart xampp. Now try send your email with your mail() function again.

You can find complete information here

Best Answer
Best Answer
Answered By 0 points N/A #84566

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 the website

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 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:


           <?php  phpinfo()  ?>



                  $to='[email protected]';
                  $body='Would you like to join us?';
                  $from='[email protected]';

7. You can then test by typing the URL

Hope this can help.


Answered By 0 points N/A #197072

PHP error with mail() function on xamp



Run this script on your localhost.





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";



//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' />






Login/Register to Answer

Related Questions