entete eBusiness.be
imagegauche
 
 




La FAQ eBusiness

FAQ  > Programming and technique  > CGI > How to specify a return address for mails sent from CGI / PHP scripts.

It’s possible (and even advised) to specify and address (the return path) by adding a parameter to the program mail sending.

-  in PHP :
Sending mail in PHP is done by using the function mail(). To specify a return address, you have to use the 5th parameter of the function that allows to pass additional information to SendMail. Example:


$to = 'utilisateur@domaine.com';
$subject = "sujet";
$corps_total = "Mon message";
$entetemail_n = "From: webmaster@$SERVER_NAME\nReply-To: webmaster@$SERVER_NAME\n";
mail($to, $subject, $corps_total,$entetemail_n,"-fpostmaster@$SERVER_NAME");

The 5th parameter (-fpostmaster@$SERVER_NAME) is thus going to force the return address to postmaster@VOTRE_DOMAINE. $SERVER_NAME is a PHP variable that holds your domain name.

-  in CGI / Perl :
Generally, you have to show the path to sendmail in the script (/usr/sbin/sendmail), you have to add a parameter behind : $mail_path = '/usr/sbin/sendmail -tfpostmaster@VOTREDOMAINE.COM';


rect