Monday, July 22, 2024
HomeBusinessHow to catch emails sent with PHP on your local server

How to catch emails sent with PHP on your local server

Date:

Related stories

Play Crazy Time and Win Big

Crazy Time is an exciting live casino game that...

Starzbet APP: Features and User Experience

In the rapidly evolving landscape of online betting, accessibility...

Hassle-Free Starzbet Giriş: Start Betting Instantly

Starzbet Giriş, or login, is your gateway to a...

Get the Latest Updates on Starzbet Twitter

In the fast-paced world of online gaming and betting,...

Starzbet Güncel Giriş: Your Key to Winning

In the ever-evolving landscape of online betting, staying ahead...
spot_img

aWhen developing websites using PHP on your local server, it’s very useful to see all outgoing emails from your PHP application, if you use the mail() PHP function. This is even more important if you develop on base of a CMS, where you can use various emails templates, field tokens and many other things that you first want to test locally before you push it to your online dev environment. This tutorial explains how to get these emails stored as textfiles in your local folder (every email as a single textfile), in a Linux environment with Apache and PHP set up. I personally use Kubuntu 12.4, but this approach should be pretty similar to any other Linux distribution.

First, create a folder for your outgoing mail. We will create it in under /var/log/ where all the logs are stored:

$ sudo mkdir /var/log/mail

Create file /usr/local/bin/sendmail using your favorite text editor, I normally use Nano editor:

$ sudo nano /usr/local/bin/sendmail

Add following PHP script to this new “sendmail” file:

#!/usr/bin/php
<?php
$input = file_get_contents('php://stdin');
preg_match('|^To: (.*)|', $input, $matches);
$filename = tempnam('/var/log/mail', $matches[1] . '.');
file_put_contents($filename, $input);

This is where the magic happens and emails sent from PHP are stored as textfiles. The email address is extracted from the full email using regular expression, and used as the filename base – the tempnam() function creates a random filename with the email address used as filename prefix. You can alter this part however you want, for example include a timestamp in the filename.

We need to link our PHP script to PHP’s sendmail functionality. Edit your php.ini file and set the sendmail_path setting as following:

sendmail_path = /usr/local/bin/sendmail

If you use Ubuntu/Kubuntu 12.4, your php.ini file is normally located at /etc/php5/apache2/php.ini. You can find your php.ini location also using the phpinfo() function, where you look for “Loaded Configuration File” value in the function’s output.

Now we need to set permissions for new files/folders:

$ sudo chmod 755 /usr/local/bin/sendmail
$ sudo chmod 777 /var/log/mail

Restart apache:

$ sudo /etc/init.d/apache2 restart

And that’s it! You can now try to send an email using PHP’s mail() function and check the /var/log/mail folder.

Latest stories

spot_img
https://stienus.ac.id/public/live/
https://stienus.ac.id/wp-includes/scatter/
https://stienus.ac.id/wp-includes/sbobet/
https://stienus.ac.id/-/sv388/
https://web.unlip.ac.id/wp-includes/scatter-hitam/
sabung ayam online
slot mahjong
https://smkn1nabire.sch.id/
akun pro jepang
Toto Togel 4D
akun pro thailand
https://sipita.akmt.ac.id/ttd/jmw/
https://akmt.ac.id/wp-content/plugins/cas/
https://akmt.ac.id/wp-content/plugins/caq/
https://sta-afc-ob.com/wp-content/uploads/2020/
https://sta-afc-ob.com/wp-content/uploads/2020/xgacor/
http://unitycolleges.co.in/1_2_1/terbaru/
https://diabeticregulator.com/images/joker/
https://kodimariimpex.com/img/slot-online/
https://mynasolutions.com/includes/gampang-menang/
https://stienus.ac.id/-/xgacor/
https://perpustakaan.ithb.ac.id/files/chat/
https://gosyensejahterautama.co.id/core/vendor/split/
https://gosyensejahterautama.co.id/core/vendor/lan/
https://lp2m.akmt.ac.id/-/xgacor/
https://mbig.bakrie.ac.id/config/-/max/
https://mbig.bakrie.ac.id/error/-/xbitxx/
https://ma.arrahmat-majalengka.sch.id/lib/ws168/
https://ma.arrahmat-majalengka.sch.id/lib/mix/
https://elearning.smpn2jayapura.sch.id/-/xgacor/
https://event.potensiaskill.com/defe/
https://event.potensiaskill.com/ceo/
https://blueedenscraptrading.com/zuu/
https://infinitotravel.com.ar/
https://laotomana.com.ar/
https://portal.stiemadani.ac.id/vendor/lib/mix/
https://portal.stiemadani.ac.id/vendor/lib/hitam/
TANGKASNET/
AKUN PRO PLATINUM
https://rajawalitanjungsari.com
sv388
casino online
agen sbobet
sabung ayam online
mahjong ways 2
scatter hitam
slot thailand
slot thailand
indobola77
indobola77
sabung ayam online
slot777
slot gacor
indomax88
indomax88
slot gacor
bandar303
bandar303
bandar303
Juara303
indobit88
master303 slot
master303 slot
Scatter Hitam
sabung ayam online
slot gacor
bola gacor
akun pro thailand
Sabung Ayam Online
https://sma1polanharjo.sch.id/
Casino Online
https://sma1baekudus.sch.id/
https://realcount-bundaenie.com/
https://operator-bsnpgkotabekasi.com/
https://bsnpgkotabekasi.com/
slot thailand
sv388
sabung ayam online
sv388
sabung ayam online
slot gacor
slot zeus
https://ela.p3tik.unisma.ac.id/
sbobet
sv388
sbobet
Zeus Slot
Akun Jp
Zeus Slot
Slot Thailand
Scatter Hitam
Slot777
Sv388
Akun Demo Slot
Slot Gacor