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

Answer: 
Try with this library:

[PHPMailer](https://github.com/PHPMailer/PHPMailer)

You can use smtp instead of sendmail.
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

```