Setting Up a Ubuntu/Apache/PHP MAChine to Send Email

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.

  1. Edit the sendmail config file on the Apache server:

    sudo nano /etc/mail/sendmail.mc
  2. 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.')dnl
  3. Save the file and exit.

  4. Update the sendmail setup in the command prompt:

    sudo sendmailconfig

    Follow the steps, I said yes to everything

  5. Restart sendmail:

    sudo service sendmail restart
  6. 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



Leave a reply



Submit