Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

How do I set the Return-Path, etc mail headers via PHP?

Discussion in 'E-mail Discussion' started by simpleupdates, Jun 18, 2008.

  1. simpleupdates

    simpleupdates Member

    Joined:
    Jan 17, 2005
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    151
    Hi all,

    We have a php function that sends an email:
    function send_mail($to, $fromemail, $fromname, $bounce_email, $message, $subject) {
    // To send HTML mail, the Content-type header must be set
    for($i=0;$i<count($to);$i++) {
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
    $headers .= "Return-path: <{$bounce_email}>\r\n";
    $headers .= "Errors-To: <$bounce_email>\r\n";
    // Additional headers
    $headers .= "To: {$to[$i][1]} <{$to[$i][0]}>" . "\r\n";
    $headers .= "From: {$fromname} <{$fromemail}>" . "\r\n";
    // Mail it
    mail($to[$i][0], $subject, $message, $headers, "f");
    }
    }


    However, when we use this function, the server changes the "Return-path" header to:
    Return-path: nobody@rootserverurl.com

    We need this email to be "bounce@accountname.com" as defined in: $bounce_email.

    How would we change it from the "nobody" default?
     
  2. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,762
    Likes Received:
    116
    Trophy Points:
    343
    cPanel Access Level:
    Root Administrator
    You have to specify this in the fifth parameter of the mail() function:

    PHP:
    mail(tosubjectmessageheaders"-fbounce@accountname.com");
    See:

    http://us2.php.net/manual/en/function.mail.php

    for more information. Please note that return path is also called the envelope-sender
     
  3. simpleupdates

    simpleupdates Member

    Joined:
    Jan 17, 2005
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    151
    Thanks!

    Your message was the key. It works.

    Thanks so much!
     
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice