0

I want to send mail using mail function using php. I have suffered from this error:

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 index.php on line 3

<?php

 if(isset($_POST['submit'])){

  if(mail('myemailhere@domain.com', 'Requirement', $_POST['requirement'])){

   echo "Done";

  } else{

  echo "Done";

  }
 }
?>

Thanks in advance.

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Mike
  • 21
  • 1
  • 5
  • 1
    Maybe helpful:- https://stackoverflow.com/questions/19132171/send-email-from-localhost-running-xammp-in-php-using-gmail-mail-server – Alive to die - Anant Jun 18 '19 at 06:19
  • I tried now i am having the error like this: Warning: mail(): Bad Message Return Path in index.php on line 3. – Mike Jun 18 '19 at 06:34
  • Of course, that's a huge step-up, but I highly recommend you to try some 3rd party library for sending emails, like `PHPMailer` or `nette/mail`. The thing is, mail is a complex topic these days due to spam protection, sender verification, and many other things. Any decent library allows you to abstract away from this, and switch transport if needed with few config file manipulations. Also, you might want to use some ouside service to send emails, because most of the time mail from localhost just does not go through. For testing, service like `mailtrap.io` is pretty good and easy to setup. – alx Jun 18 '19 at 08:49
  • Thanks a lot. It worked. – Mike Jun 27 '19 at 17:24

0 Answers0