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 = "test@test.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
When i execute the code, It takes very l开发者_运维问答ong time and finally echo the message as Mail Sent. Is there any possibilities to fix this ?
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('recipient@somewhere.com', 'the subject', 'the message', null, '-fsender@somewhere.com');
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
This answer helped me https://serverfault.com/a/221894/186680
Postfix and sendmail where installed. Removed sendmail Yum remove sendmail
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.
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.
精彩评论