Simple script for testing the sending of mail on a local Linux server
First, create a shell script fakesendmail.sh in the folder /usr/bin/
touch /usr/bin/fakesendmail.sh
Add the following script to this file:
#!/bin/sh
prefix="/var/www/mail"
numPath="/var/www/mail"if [ ! -f $numPath/num ]; then
echo "0" > $numPath/num
fi
num=`cat $numPath/num`
num=$(($num + 1))
echo $num > $numPath/numname="$prefix/letter_$num.txt"
while read line
do
echo $line >> $name
done
/bin/true
Set permissions and make it executable
sudo chown root:root /usr/bin/fakesendmail.sh
sudo chmod 755 /usr/bin/fakesendmail.sh
chmod +x /usr/bin/fakesendmail.sh
Create folders for local mail and set permissions
sudo mkdir /var/www/mail
sudo chmod -R 777 /var/www/mail
Set path to your script in php.ini
sendmail_path = /usr/bin/fakesendmail.sh
Restart PHP.
service php8.3-fpm restart
To verify the sending of mail can use a simple php script
<?php
$to = 'root@localhost';
$subject = 'Test letter';
$message = 'Hello.It works!';
$headers = 'From: 2hostatto@gmail.com' . "\r\n" .
'Reply-To: 2hostatto@egmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();$send = mail($to, $subject, $message, $headers);
echo ($send) ? "Letter was sent!" : "Error sent!";
?>
If everything is fine in the folder /var/www/mail/ you will see the file letter_1.txt. This is your sent letter.
File num it`s letter counter.
Note: If the email was not sent, check the permissions on the created files and folders.