0

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" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <my.real.mail@gmail.com>' . "\r\n";

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?

user3712139
  • 51
  • 2
  • 5
  • Is it a local computer? I think so because of the computer name. It is mostly not possible to send emails from home network. – Richard May 19 '15 at 11:25
  • If your sendmail setup is valid, and your firewall allows port 25 outbound, then almost certainly your problem is that gmail is treating the e-mail as spam – Chris Lear May 19 '15 at 11:26
  • look at your relay, your mail server is installed locally with no connection to the public ip on port 25, you need to be on public ip to send a mail from your computer. – Sourabh Kumar Sharma May 19 '15 at 11:26
  • Can't be sure, but reading http://askubuntu.com/questions/326879/sendmail-very-slow-etc-hosts-configuration might be of use. – Jonnix May 19 '15 at 11:29
  • Yes is a local computer, i noticed that i received some mail (marked as spam from gmail) but i think i sent them hour ago..i could have broke my configurations in the meanwhile! – user3712139 May 19 '15 at 11:47
  • If gmail thinks e-mail looks spammy, it will delay delivery. – Chris Lear May 19 '15 at 13:55
  • Problem solved, i had to edit my resolv.conf file adding nameserver 8.8.8.8 and 8.8.4.4 and now works fine. Regarding sendmail is sufficient the installation, no need to change any configuration evenf if, obviously, mail are marked as spam but at the moment is fine for me, thank you. – user3712139 May 22 '15 at 09:19

1 Answers1

0

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

Community
  • 1
  • 1
Sanjay Mohnani
  • 990
  • 7
  • 18
  • It is possible to send from localhost, actually. But it requires sendmail configuration, not php configuration. If sendmail is configured to always use gmail as a smarthost, using the submission port and an authenticated (encrypted) connection, then the plain php mail() command will work fine. But maybe it's easier to just use something like PHPMailer. – Chris Lear May 19 '15 at 11:33
  • Yes, You can do by setting up details under php.ini. This post will help you for this. http://stackoverflow.com/questions/112190/php-ini-smtp-how-do-you-pass-username-password – Sanjay Mohnani May 19 '15 at 11:39
  • Some of the mail i sent with the configuration above arrived in my gmail marked as spam, but it required at least an hour to send and receive the mail – user3712139 May 19 '15 at 11:48
  • There are various criteria in which GMAIL will mark your email as spam. Try to figure those out. It depends on your sender IP Address, your subject, content, sender email address and many more. – Sanjay Mohnani May 19 '15 at 11:51
  • You can't really avoid the e-mail being marked as spam if you're delivering on port 25 without authenticating from a dynamic ip address. You can't do much about the ip address, but you can deliver via an authenticated smarthost by either using phpmailer or setting up sendmail appropriately. Note that you can't use php.ini to configure authentication. – Chris Lear May 19 '15 at 13:57