Technology TidBits

Answers to various technical questions on php programming, mysql, linux, and many more categories.



Add comment:
Name:
Email:
Comment: *
(Use BBcode - No HTML)


You MUST answer this simple math equation - to prevent spammers: 1 + 13 =  


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>






Powered by KnowledgebasePublisher 1.1
Superb Internet
Content provided by Roberts WebForge, Inc.