|
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:
- dpkg -l | grep sendmail
- dpkg -l | grep postfix
- dpkg -l | grep exim4
Copy the Code On CentOS/RHEL:
- rpm -qa | grep sendmail
- rpm -qa | grep postfix
- 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):
- sudo apt update
- 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):
- sudo apt update
- sudo apt install sendmail
- sudo sendmailconfig # Follow the interactive prompts to configure it.
Copy the Code For CentOS/RHEL (recommended: Postfix):
- sudo yum update
- sudo yum install postfix mailx
- sudo systemctl enable postfix
- sudo systemctl start postfix
Copy the Code You might also need to configure your firewall to allow SMTP traffic:
- sudo firewall-cmd --add-service=smtp --permanent
- sudo firewall-cmd --reload
Copy the Code Alternatively, to install Sendmail:
- sudo yum update
- sudo yum install sendmail sendmail-cf
- sudo systemctl enable sendmail
- 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:
- which sendmail
- 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:
- 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:
- 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 :
- 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:
- 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.
|
|