Technology TidBits

Answers to various technical questions on php programming, mysql, linux, and many more categories.
25% off Hosting at HostGator.com:
Use Code techbits25



How can I get bounced emails from my email CGI or PHP script?

Last updated: 06/30/2009

It seems that most cgi / php scripts that send email do not get bounces.  So you never know if the email address was legitimate or not.  This is especially problematic when sending automated newsletter emails or updates.  Ideally, you want bad addresses to bounce back so you can remove them from your list.  Here's what I found out after some research.

The short answer is that you need to add this to the email headers:

Return-Path:  you@yourdomain.com

Here's a sample php script to test the concept (edit the $to, $from, and $bounce variables accordingly:

<?
$to = junkaddress@yourdomain.com;
$from = "you@yourdomain.com";
$bounce = you@yourdomain.com;

mail("$to","Test Email","This is a message.\n\nTo: $to\nFrom: $from\nBounce: $bounce\n","From: $from\r\nReturn-Path: $bounce\r\n");
?>

Ok, email sent! <br>
To: <?=$to;?><br>
From: <?=$from;?><br>
Bounce: <?=$bounce;?><br>


blog comments powered by Disqus
Have your own Tech-bit to contribute? Submit it here

Other questions in this category:
What's the format for Perl's stat command?
How do I find a list of perl modules on my system?
How can I create a CSV from a CGI script?
How can I get the time in Perl?
How can I redirect users to a static page after running a CGI program?
How do I go about writing a Perl module?
How do I create a hash of lists in Perl?
I want to uppercase all the words in a string
How can I get multiple checkbox values using CGI.pm?
How do a I fix a "bad interpreter" error with my CGI script?
I need to get rid of all non-alphanumeric characters from a string - how can I do it?
How can I keep leading zeros when building a CSV file?
How to print a hash of hashes for debugging
How do I get the username of the user running the script?
How do I fix this error: Argument "O_RD" isn't numeric in subroutine entry at /usr/lib/perl5/5.8.5/i386-linux-thread-multi/DB_Fi le.pm line 278
How can I get my Perl code indented to look nice?
Perl regular expression to find non-printable characters
How can I tie into my vbulletin user database from a perl script?
Checking for spam in perl scripts
My perl scripts keep timing out on IIS.
Why use Perl
CGI script variables are missing using CGI.pm
Useful script to track spammers connecting to your server



Powered by KnowledgebasePublisher 1.1
Host Gator
Content provided by Roberts WebForge, Inc.