Store e-mail locally, Ubuntu sendmail stub for Php

Ubuntu does not come with packages for sending emails. Consider a method that saves messages to a folder in separate files.

1. You need to create a shell script in /usr/bin/f_mail.sh :

sudo nano /usr/bin/f_mail.sh

In which we will add the code:

#!/bin/sh
prefix=" /var/www/sendmail/new "
numPath=" /var/www/sendmail "

if [ ! -f $numPath/num ]; then
echo "0" > $numPath/num
fi
num=`cat $numPath/num`
num=$(($num + 1))
echo $num > $numPath/num

name="$prefix/letter_$num.html"
while read line
do
echo $line >> $name
done
chmod 777 $name
/bin/true

/var/www/sendmail/new - the path where files with emails will be saved.

/var/www/sendmail - shared folder for the script.

2. Grant rights to the script (perhaps not for everyone this is required):

sudo chown root:root /usr/bin/f_mail.sh

sudo chmod 755 /usr/bin/f_mail.sh

3. Let's create the folder structure required for work:

sudo mkdir /var/www/sendmail/new && cd /var/www/sendmail/new && sudo mkdir cur && sudo mkdir new && sudo mkdir tmp && sudo chmod -R 777 /var/www/sendmail/new

4. Recipe in php.ini :

v5.6 :

/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini
/etc/php5/cgi/php.ini

v7.2 :

/etc/php/7.2/apache2/php.ini
/etc/php/7.2/cli/php.ini
/etc/php/7.2/cgi/php.ini

In the required version, in the php.ini files, add the code to the end or find the line ;sendmail_path and replace it with:

sendmail_path = /usr/bin/f_mail.sh

1727 2

Comments

alex, я вижу 2 причины почему так может быть. Не в том php.ini прописан sendmail_path или вы используете для отправки не протокол "sendmail" а "mail". Но в любом случае могу уже не помнить. Напишите в какой-то из контактов, посмотрим, а потом я тут это опишу.
Сделал все так как написано в статье, не работает.
You have to log in to leave a comment. Sign in

Similar articles