Reputation: 8238
I am using Ubuntu.I installed sendmail in my local host using the following command
sudo apt-get install sendmail
Now I would like to check whether mail goes from my localhost using following php code.
<?php
$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
When i execute the code, It takes very long time and finally echo the message as Mail Sent. Is there any possibilities to fix this ?
Upvotes: 18
Views: 20525
Reputation: 160
Edit the file /etc/hosts
and make sure the first line is the following:
127.0.0.1 localhost.localdomain localhost myhostname
Edit the sendmail
configuration file ( /etc/mail/sendmail.cf
in Ubuntu) and Uncomment the line #O
:
O HostsFile=/etc/hosts
Restart the computer, or run sudo service sendmail restart
.
The computer should boot up much faster now and the mail()
function should return almost immediately.
HOWEVER, the emails won't actually be sent unless you follow step 5.
You must new use the sendmail -f
option whenever using the mail function.
For example:
mail('[email protected]', 'the subject', 'the message', null, '[email protected]');
Upvotes: 16
Reputation: 1040
This answer helped me https://serverfault.com/a/221894/186680
Postfix and sendmail where installed. Removed sendmail Yum remove sendmail
Upvotes: 2
Reputation: 1509
I know this question has already been answered, but I'm posting this in the hope it may help someone else looking for a different solution to this issue.
For me, I just needed to put my server's Fully Qualified Domain Name (FQDN) into /etc/mailname
. For example: server.example.com
.
Restart Sendmail to apply the changes.
$ sudo service sendmail restart
Upvotes: 3
Reputation: 189820
Unless you know Sendmail well, you are probably bettter off installing some other MTA. ssmtpd
was already suggested in another answer; a common choice is Posfix.
Upvotes: 0
Reputation: 1998
The delay is usually indicating a DNS time-out. Is your machine configured with proper DNS entries? I would try doing a test using mail on the command line as this would isolate the issue.
Upvotes: 0