configure sendmail for php email()

General Tech Bugs & Fixes 3 years ago

2.38K 2 0 0 0

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 years ago

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 views
0 shares

profilepic.png
manpreet 3 years ago

 

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

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Similar Forum