Thursday, November 7, 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

The Art of Betting in Live Casino Games: Strategies and Insights for Success

Live casino gaming has surged in popularity over recent...

Explore the Best Online Gambling Platforms at Macaubet

The online gambling industry has seen remarkable growth in...

How to Redeem Bonus New Member 100 and Play Slot Gacor Effortlessly

In the competitive world of online casinos, players are...

Experience the Thrill: Online Pokies That Pay Real Money

Online pokies have surged in popularity, captivating millions of...

How to Access the Latest Promotions with Starzbet Yeni GiriÅŸ

In the fast-paced world of online betting, promotions play...
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
Slot77Jp link slot gacor slot maxwin situs slot online suhu138 suhu138 slot scatter hitam

Warning: file_get_contents(): Filename cannot be empty in /home/u117677723/domains/martinvalasek.com/public_html/wp-content/themes/Newspaper/footer.php on line 6
didascaliasdelteatrocaminito.com
glenellynrent.com
gypsumboardequipment.com
realseller.org
https://harrysphone.com/upin
gyergyoalfalu.ro/tokek
vipokno.by/gokil
winjospg.com
winjos801.com/
www.logansquarerent.com
internationalfintech.com/bamsz
pancen.id
winjosjakrata.com
winlotrebandung.com
condowizard.ca
jawatoto889.com

hikaribet1.com
heylink.me/hikaribet
www.nomadsumc.org
condowizard.ca/aromatoto
euro2024gol.com
www.imaracorp.com
daftarsekaibos.com
stuffyoucanuse.org/juragan
Situs Togel Resmi
Toto Macau 4d
Aromatoto
Lippototo
Mbahtoto
Winjos
152.42.229.23
bandarlotre126.com
heylink.me/sekaipro
www.get-coachoutletsonline.com
wholesalejerseyslord.com
Fajartoto
Situs Togel
Toto Macau