web of unni

About | GuestBook | Add WebOfUnni to Google ToolBar

Download Day

September 27, 2007

Overriding default Return-path in mail header using php mail

Filed under: mail, php — unni @ 2:15 pm

When sending mails using php script default return path in mail header will be something like nobody@host.com. By adding some additional parameter in php mail function we can replace the default return path.

Php mail function has 5 parameters

1. To
2. subject
3. message
4. additional_headers
5. additional_parameters

So when sending mails using php mail function we can add -f myname@myself.com in additional_parameters section to replace the return path with our mail id.

Sample code for replacing return path with wemaster@example.com is given below

<?php
$to = ‘unnikrishnan.a@gmail.com’;
$subject = ‘the subject’;
$message = ‘hello’;
$headers = ‘From: webmaster@example.com’ . “\r\n” .
‘Reply-To: webmaster@example.com’ . “\r\n” .
‘X-Mailer: PHP/’ . phpversion();

$result = mail($to, $subject, $message, $headers, “-fwemaster@example.com”);
echo $result;
?>

In the mail header we can see the return path as wemaster@example.com

Delivered-To: unnikrishnan.a@gmail.com
Received: by 10.90.26.7 with SMTP id 7cs24300agz;
Thu, 9 Aug 2007 07:12:35 -0700 (PDT)
Received: by 10.115.77.1 with SMTP id e1mr1363695wal.1186668755167;
Thu, 09 Aug 2007 07:12:35 -0700 (PDT)
Return-Path: <wemaster@example.com>

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Created and maintained by Unnikrishnan
Hosted by Host cats