Using Sendmail on development server

August 17, 2014 2.7k views

I'm in the process of moving a site from GoDaddy to a LAMP Ubuntu 14.0.4. on DigitalOcean. So far everything is working except for mail.

I installed Sendmail, but when I test the contact form on the site (which uses PHPMailer) it fails to reach the recipient. When I look in /var/spool/mail/root I see messages like this:

The original message was received at Sat, 16 Aug 2014 23:56:55 -0400
from localhost []

   ----- The following addresses had permanent fatal errors -----
    (reason: 550 5.2.0 <www-data@store> From: Domain is invalid. Please provide a valid From: IB506  <>) 

I'm leaving the email accounts for the website at GoDaddy, so I'm not sure what to try next. Can someone point me in the right direction?

1 Answer

The problem is the "www-data@store" address that apache is trying to send the email from. I run into this all the time and there is always a different solution. Usually it is a programming issue.

Basically, you have to make sure that the 'From' address for the email is a valid and locally resolvable email address. So, depending on what software you are using to send the email the fix will vary.

If it's something you have developed in PHP yourself, make sure you set the 'From' header in the $additional_headers parameter. eg:

$from = '';
$additional_headers = array('From' => $from);
mail('', 'Test Email', 'This is the content', $additional_headers);

If that doesn't work, you can also try setting it as an additional_parameter and send the sendmail -f argument that will explicitly set the from address. This is usually a catchall solution. eg:

$from = '';
$additional_headers = array('From' => $from);
mail('', 'Test Email', 'This is the content', $additional_headers, '-f ' . $from);
Have another answer? Share your knowledge.