0

I am trying to send a very basic mail with PHP using the below code;

if (mail('mymail@gmail.com','Test mail','Testing mail function!'))
{
    echo "Email was sent successfully!";
}
else
{
    echo "Email was not sent!";
}

However, the output is always 'Email was not sent'. I am running this script locally on my machine using Xaamp.

I already tried to research a solution for this but I had no luck. It seems like it's something to do with server configuration. I tried to modify sendmail in php.ini but it still didn't work.

Any help on this is greatly appreciated.

Thank you.

forseth31
  • 83
  • 1
  • 7

3 Answers3

1

Try with this library:

PHPMailer

You can use smtp instead of sendmail.

JM Mayo
  • 309
  • 1
  • 6
0

Mail Settings in XAMPP

$this->email->from('mygmail@gmail.com', 'myname');//your mail address and name
$this->email->to('target@gmail.com'); //receiver mail

$this->email->subject('testing');
$this->email->message($message);

$this->email->send(); //sending mail
Configuration in sendmail.ini

path c:\xampp\sendmail\sendmail.ini

Configurations

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=myemail@gmail.com
auth_password=yourgmailpassword
force_sender=myemail@gmail.com
in php.ini

path c:\xampp\xampp\php\php.ini

[mail function]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
 sendmail_from = yourmail@gmail.com
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
0

You need to run Mercury to simulate a mail server, this is a Mercury tutorial: http://system66.blogspot.com.es/2010/01/how-to-send-mail-from-localhost-with.html

Or you can use a PHPMailer.

Nomad Webcode
  • 816
  • 5
  • 9