configure sendmail for php email()

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 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?

profilepic.png
manpreet 2 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.