sending email with PHP sendmail not working for primary domain
Apache was trying to handle the email locally on our server. When I looked at the log response I saw it was returning the following error.
User unknown
550 5.1.1 recepient@example.com
After following these steps the email was routed to the correct mail server. My setup is Ubuntu 12.04 with PHP 5 Apache2 and Sendmail.
Edit the sendmail config file on the Apache server:
sudo nano /etc/mail/sendmail.mc
At the end of the file add the following lines of code to handle email correctly:
define(`MAIL_HUB', `example.com.')dnl define(`LOCAL_RELAY',
`example.com.')dnlSave the file and exit.
Update the sendmail setup in the command prompt:
sudo sendmailconfig
Follow the steps, I said yes to everything
Restart sendmail:
sudo service sendmail restart
Try sending the email again. It should work now.
PHP mail() fails to send mails | Postfix configuration | Apache 2 | Ubuntu 16.04
Even though I probably messed up some of the settings by trying to fix my issue, php mail happened to work fine on any other work environment aside from the ones at my place. By doing some research I found out that some people who had the same issues I had (and still have) were told that the issues probably came from the internet provider (Orange fr).
I don't know whether it makes sense or not, but in my case, empirical evidences seem to point that way.
I will now set this question as answered.
php mail() not sending mail or returning error message, worked on my system (localhost) but not on ubuntu/apache2
Emails sent directly by a PHP script in this way typically get marked as junk or spam by the major email providers. If you start sending them in any quantity, your email address (and possibly domain) will end up on Spamhaus and other blacklists.
If you need to send individualized emails like your example above, consider using a service like SendGrid or Amazon Simple Email Service.
How can apache be allowed to send email?
First you have to check if permission are correct. Here is the permission below in my system
# ls -l /usr/sbin/sendmail.sendmail
-r-xr-sr-x root smmsp /usr/sbin/sendmail.sendmail
# ls -l /var/spool/clientmqueue
drwxrwx--- smmsp smmsp /var/spool/clientmqueue
If your permissions or ownership is wrong then change it using chown and chmod.
If the above is right then disable selinux or if you want selinux enabled use chcon to set the correct selinux context.
http://docs.fedoraproject.org/en-US/Fedora/13/html/Security-Enhanced_Linux/sect-Security-Enhanced_Linux-Working_with_SELinux-SELinux_Contexts_Labeling_Files.html
For disabling selinux temporarily use #setenforce 0
Related Topics
How to Discover Rss Feeds for a Given Url
Have Gd Get Image from Binary String
Yii2 Global Filter/Behavior to Force User to Authenticate First
Best Way to Document Array Options in PHPdoc
What Is the Concept of Service Container in Laravel
How to Work with Many-To-Many Relations in Yii2
Checking for Empty Arrays: Count VS Empty
PHP - a Db Abstraction Layer Use Static Class VS Singleton Object
Scrape Web Site Generated by JavaScript
Best Way to Check If a Url Is Valid
Image Upload Storage Strategies
Passing Value from PHP Script to Python Script
Symfony2 Collection of Entities - How to Add/Remove Association with Existing Entities
Rename an Uploaded File with PHP But Keep the Extension