0

Recently I installed sendmail in Ubuntu

sudo apt install sendmail
sudo sendmailconfig

When I try to send mail using php email(); function to send email

$to = "myemail@gmail.com";
$subject = "Mail Test at ".strftime("%T", time());
$message = "This is a test.";
$message = wordwrap($message, 70);
$from = "anotheremail@gmail.com";
$headers = "From: {$from}";
$result = mail($to, $subject, $message, $headers);
echo $result ? "sent" : "error";

Now when I browse the php site I get sent message but I don't get email (in my official email). Can anybody help?

0

You might need to add your hostname to /etc/hosts (find the line with 127.0.0.1 and append your hostname):

127.0.0.1 localhost localhost.localdomain your_hostname_here

Try restarting apache:

$> sudo service apache2 restart

Please keep in mind that:

  1. mail returns success (true) if it transported your mail successfully to the configured MTA. This does not mean, that your MTA actually sent any mail.
  2. modern mail servers might not accept your email, since spam filters (dns lookup, sender verification, ...) might be active and prevent delivery.

You can check sendmails mail queue anytime with the command

$> mailq

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.