This question already has an answer here:
i'm developing a Web Application in php and at some point i need to send a confirmation mail. Sendmail in installed but when i try to run this code it load the page really slow and nothing happens.
<?php
$to = "my.real.mail@gmail.com";
$subject = "Confimation";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "
";
$headers .= "Content-type:text/html;charset=UTF-8" . "
";
// More headers
$headers .= 'From: <my.real.mail@gmail.com>' . "
";
mail($to,$subject,$message,$headers);
?>
This is the mail.log
May 19 13:18:02 al-Inspiron-5548 sendmail[6934]: t4JBI24R006934: from=www-data, size=416, class=0, nrcpts=0, msgid=<201505191118.t4JBI24R006934@localhost.localdomain>, relay=www-data@localhost
May 19 13:18:02 al-Inspiron-5548 sendmail[6936]: t4JBI2ex006936: from=www-data, size=416, class=0, nrcpts=0, msgid=<201505191118.t4JBI2ex006936@localhost.localdomain>, relay=www-data@localhost
Someone can help me?
</div>
To send any mail to another server, you should have your own mail server's details.
Here, you are trying to send email to GMAIL with your localhost, which is not possible. You should setup your own SMTP details of your server OR your sender email's (Gmail, Yahoo etc...).
PHP has some cool libraries to help you out like PHPMailer.
There's already post which might help you. Sending email with PHP from SMTP SERVER
All the best !!