вторник, 1 ноября 2011 г.

PHP sendmail, save mails in local filesystem folder

Params:
OS: Gentoo
Language: PHP 5.3.8

Problem:
Save mails sended from PHP script in local filesystem folder.
View them by KMail

Solution:
Make all changes relative to your distro.
1) Create script fakesendmail.sh

#!/bin/sh 
prefix="/home/<my_username>/temp/sendmail/new"
numPath="/home/<my_username>/temp/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.txt"
while read line
do
     echo $line >> $name
done
chmod 777 $name


/bin/true


I saved it in folder /home/<my_username>/Applications/

Don't forget set appropriate pathes in script.

2) Make this script executable: console> chmod +x fakesendmail.sh


3) Create folders for mails: 


console> mkdir 
/home/<my_username>/temp/sendmail/


console> mkdir 
/home/<my_username>/temp/sendmail/cur


console> mkdir 
/home/<my_username>/temp/sendmail/new


console> mkdir 
/home/<my_username>/temp/sendmail/tmp


4) Change folder properties: console> chmod 777 -R 
/home/<my_username>/temp/sendmail/


5) Make changes in php.ini file (on gentoo: /etc/php/apache2-php5.3/php.ini)


Change path to sendmail script to our new script:


sendmail_path = /home/<my_username>/Applications/fakesendmail.sh
6) Open KMail and create new incoming account.
Kontact->Settings->Configure KMail->Accounts->Add Account
In opened window choose "Maildir mailbox" and set appropriate folder "
/home/<my_username>/temp/sendmail"



Комментариев нет:

Отправить комментарий