Forgot password
 Register account
View 117|Reply 0

Linux sendmail

[Copy link]

3226

Threads

7843

Posts

52

Reputation

Show all posts

hbghlyj posted 2025-6-20 11:42 |Read mode
The error message "sh: 1: /usr/sbin/sendmail: not found" indicates that the system cannot locate the sendmail executable at the specified path (/usr/sbin/sendmail). This is a common issue and usually means one of the following:
  • sendmail (or another MTA) is not installed.
  • A different MTA (like Postfix or Exim) is installed, and its sendmail compatibility binary is not linked or is in a different location.
  • The PHP sendmail_path in php.ini is pointing to an incorrect location.
Here's a step-by-step approach to diagnose and fix this:
Step 1: Check if sendmail (or another MTA) is installed
First, let's see if sendmail or a common alternative like postfix or exim4 is already present on your system.
On Debian/Ubuntu:
  1. dpkg -l | grep sendmail
  2. dpkg -l | grep postfix
  3. dpkg -l | grep exim4
Copy the Code
On CentOS/RHEL:
  1. rpm -qa | grep sendmail
  2. rpm -qa | grep postfix
  3. rpm -qa | grep exim
Copy the Code
If none of these commands return any installed packages, it's highly likely you don't have an MTA installed.
Step 2: Install an MTA (if not already installed)
It's generally recommended to use postfix for a simpler setup, as sendmail can be quite complex to configure from scratch. However, if you specifically want sendmail, you can install it.
For Debian/Ubuntu (recommended: Postfix for ease of use):
  1. sudo apt update
  2. sudo apt install postfix mailutils
Copy the Code
During the Postfix installation, you'll usually get a configuration screen. Choose "Internet Site" for general email sending and follow the prompts, providing your system's hostname/domain if asked. mailutils provides the mail command, which often creates a symbolic link from /usr/bin/mail to the system's MTA.
Alternatively, to install Sendmail (more complex configuration):
  1. sudo apt update
  2. sudo apt install sendmail
  3. sudo sendmailconfig # Follow the interactive prompts to configure it.
Copy the Code
For CentOS/RHEL (recommended: Postfix):
  1. sudo yum update
  2. sudo yum install postfix mailx
  3. sudo systemctl enable postfix
  4. sudo systemctl start postfix
Copy the Code
You might also need to configure your firewall to allow SMTP traffic:
  1. sudo firewall-cmd --add-service=smtp --permanent
  2. sudo firewall-cmd --reload
Copy the Code
Alternatively, to install Sendmail:
  1. sudo yum update
  2. sudo yum install sendmail sendmail-cf
  3. sudo systemctl enable sendmail
  4. sudo systemctl start sendmail
Copy the Code
Again, configure your firewall if necessary for port 25.
Step 3: Verify the sendmail path and create a symbolic link (if necessary)
Even if Postfix or Exim is installed, many applications (including PHP's mail() function) expect to find a sendmail executable at /usr/sbin/sendmail. Often, the installed MTA provides a compatibility binary or wrapper at that location.
Check if the sendmail command exists and where it points:
  1. which sendmail
  2. ls -l /usr/sbin/sendmail
Copy the Code
If which sendmail returns nothing, or ls -l /usr/sbin/sendmail shows it doesn't exist or is a broken link, and you have Postfix or Exim installed, you might need to create a symbolic link:
If Postfix is installed:
  1. sudo ln -s /usr/sbin/sendmail.postfix /usr/sbin/sendmail
Copy the Code
(Sometimes it's just /usr/sbin/postfix, so you might also try sudo ln -s /usr/sbin/postfix /usr/sbin/sendmail if sendmail.postfix doesn't exist.)
If Exim is installed:
  1. sudo ln -s /usr/sbin/exim4 /usr/sbin/sendmail
Copy the Code
(Or check ls -l /usr/sbin/sendmail* to see what compatibility link Exim might provide.)
Step 4: Check PHP's sendmail_path in php.ini
If you've installed an MTA and confirmed the sendmail executable path, ensure PHP is configured to use it.
  • Find your php.ini:
    1. php -i | grep "Loaded Configuration File"
    Copy the Code
    This will show you the path to the php.ini file that PHP is currently using. Common locations include /etc/php/X.Y/cli/php.ini (for command line) and /etc/php/X.Y/fpm/php.ini or /etc/php/X.Y/apache2/php.ini (for web server).
  • Edit php.ini:Open the php.ini file with a text editor (e.g., sudo nano /etc/php/X.Y/cli/php.ini) and search for sendmail_path. Make sure it's uncommented and points to the correct location (usually /usr/sbin/sendmail -t -i):
    sendmail_path = /usr/sbin/sendmail -t -i[/code]If you're using a different MTA that doesn't provide a /usr/sbin/sendmail compatibility link, you might point it directly to the MTA's binary, e.g., sendmail_path = /usr/sbin/postfix -t -i. However, creating the symbolic link is generally the cleaner solution.
  • Restart PHP-FPM or Apache/Nginx (if running web server PHP):After modifying php.ini, you must restart your web server or PHP-FPM service for the changes to take effect.

    • For Apache: sudo systemctl restart apache2 or sudo service apache2 restart
    • For Nginx with PHP-FPM: sudo systemctl restart phpX.Y-fpm (replace X.Y with your PHP version, e.g., php8.2-fpm) or sudo service phpX.Y-fpm restart
Step 5: Test again
Once you've completed these steps, retry your php -r one-liner or your command-line mail command:
  1. php -r "var_dump(mail('your_email@example.com', 'PHP Test Subject', 'This is a test email sent from PHP via the command line.'));"
Copy the Code
And check your mail logs (/var/log/mail.log or /var/log/maillog) for detailed information about the email delivery.
This systematic approach should help you resolve the "sendmail: not found" error.

Quick Reply

Advanced Mode
B Color Image Link Quote Code Smilies
You have to log in before you can reply Login | Register account

$\LaTeX$ formula tutorial

Mobile version

2025-7-23 21:16 GMT+8

Powered by Discuz!

Processed in 0.020149 seconds, 22 queries