Sendmail with Ubuntu and PHP

Sendmail with Ubuntu and PHP

September 4, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Sendmail with Ubuntu and PHP

Troubleshooting Sendmail with Ubuntu and PHP on AWS EC2

You’re encountering an issue while trying to send emails using PHP on your Bitnami Magento installation hosted on an AWS EC2 instance running Ubuntu. Let’s dive into this problem step-by-step.

Understanding the Current Setup

Your current setup involves a Bitnami Magento deployment, which typically uses Apache and PHP-FPM for processing requests. The Bitnami stack includes Sendmail for handling email sending tasks. However, it seems there are some configuration discrepancies causing the issue.

What’s Working vs. What Isn’t

You’ve discovered that using the command line to send an email works perfectly:

echo "My test email being sent from sendmail" | /usr/sbin/sendmail toemail@mydomain.com

This indicates that Sendmail is properly installed and configured on your server.

On the other hand, running a simple PHP script doesn’t work as expected:

<?php
    $to = 'toemail@mydomain.com';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: fromemail@mydomain.com' . "\r\n" .
        'Reply-To: fromemail@mydomain.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);
?>

The Error Message

When you try to run the script using php my_php_email_test.php command in SSH or from your browser, you encounter this error:

sh: 1: /usr/bin/sendmail: not found

This suggests that PHP is unable to locate Sendmail when attempting to send an email.

Debugging the Issue

The problem lies in how PHP is configured. By default, the sendmail_path option in your PHP configuration (php.ini) might be set incorrectly or commented out. Let’s fix this:

  1. Locate your PHP configuration file: It could be /etc/php/7.x/apache2/php.ini or /etc/php/7.x/cli/php.ini, depending on whether you’re running the script from Apache (web) or SSH (command line).

  2. Open the php.ini file in a text editor with superuser privileges:

    sudo nano /path/to/your/php.ini
    
  3. Search for the following line:

    ;sendmail_path = /usr/sbin/sendmail -t -i
    
  4. Uncomment the line by removing the semicolon (;) at the beginning.

  5. Save and close the file, then restart your web server or PHP-FPM to apply changes:

    sudo systemctl restart apache2
    # or
    sudo service php-fpm restart
    

Verifying the Solution

After making these changes, try running your script again either via SSH (php my_php_email_test.php) or from within Magento. The email should now be sent successfully.

Remember that for Bitnami Magento installations specifically, you might need to configure additional settings in the config.php and env.php files located under /opt/bitnami/apps/magento/htdocs/app/etc. Ensure your SMTP configuration is correct according to this guide.

Conclusion

In conclusion, resolving this issue required a combination of understanding PHP’s email sending mechanisms and properly configuring the Sendmail path in your PHP settings. Always ensure that your server-side scripting environment (PHP) is correctly linked with the mail service (Sendmail).

If you’re still encountering difficulties or need further assistance with Magento email setup on AWS EC2, feel free to explore more resources at LaravelCompany.

Configuration Deployment Email Errors

Our network