ive been trying to set the Return-Path: header, im using mail() function;

code:::

mail($cust_email, $subject, $message,
     "From: $orders_at_eatearly\r\n"
    ."Reply-To: $orders_at_eatearly\r\n"
	."Return-Path: $orders_at_eatearly \r\n");
    ."X-Mailer: PHP/" . phpversion());

it simply will not work ive tried everything i can think of. please help.. ;( every other header i set works fine.

instead of gettin a retu with

Return-Path: <me@mydomain.com>
i get
Return-Path: me@localhost.mylocaldomain>

tw

    The return path header is added by the SMTP host. When the computer says: "MAIL FROM: xxx@xxx.com" to the remote computer,

    The PHP mail function lacks some flexibility when it comes to message headers and customizing who your email is from. To do this you'll need to have PHP manually open a socket manually to an SMTP server and talk to it by its self. I've attached a class that I use which does this.

    To use it you'll need to know the name of your web hosts SMTP server or an SMTP server you can log on to, to send your messages. If you don't set an SMTP host the class will go ahead and use PHP's mail function.

    The class can also send attachments with the message and send them in HTML format. All the encoding is wrapped in the class, all you have to worry about is the message its self. Here's an example of how the class can be used:

    <?php
      $fhwnd = fopen('test.php', 'r');
      $file = fread ($fhwnd, filesize('test.php'));
    
      fclose ($fhwnd);
    
      require ('mail.inc');
    
      $mail = new mail_message;
    
      $mail->from ('Me', 'me@myhost.com'); // this sets the actual from address header
      $mail->add_attachment ($file, 'test.txt', 'text/plain'); // add the fille retrieved earlier as an attachment
    
      $mail->add_recipient ('Mr No One', 'no_one@yahoo.com'); // add a recipient
    
      $mail->subject = 'The Subject'; // set the subject line
    
      $mail->smtp_from = 'weird@myreturn.com'; // this will set the return path
    
      $mail->smtp_host = 'post.smtp.com'; // set the host
    
      $mail->body =
    'This is the message body:
    Line1
    Line2
    Line3';
    
      $mail->send(); // send the message
    ?>
    

    Its worth doing a little reading on SMTP and mail headers as the class is not forgiving when a message is constructed in the wrong fashion.

      i seem to get this error?

      SMTP protocol faliure (503 RCPT first (#5.5.1) )

      ill keep trying different permutations but can u shead any light on this?

      thanx for your help so far...

        This response is usually sent when no recipients have been added. I assume that you did add the recipient to your class so that would mean that an error occured when it was sent to the SMTP server.

        One reason for this is that the SMTP server is closed. This means only authorised remote computrers are allowed to send emails through them. There are not many open SMTP servers out there now, becuase spammers abuse them and send huge quantities of mail from them.

        The class I sent you is made in such a way that if a recipent is denied by the SMTP server it will continue. However thinking this over, even if there are multiple recipients, if one fails the sender would like to know.

        To demonstrate what may have happened. I used telnet to try and send an email on a closed SMTP server. Heres what happened:

        220 mail.myhost.com ESMTP Postfix
        MAIL FROM: <me@myhost.com>
        250 Ok
        RCPT TO: <friend@myhost.com>
        554 <friend@myhost.com>: Relay access denied
        DATA
        503 No recipient(s).

        I then did the same thing but logged on to the SMTP server this time:

        220 mail.myhost.com ESMTP Postfix
        250 Ok
        AUTH LOGIN
        334 VXNlcm5hbWU6
        <username>
        334 UGFzc3dvcmQ6
        <password>
        235 Authentication successful
        MAIL FROM: <me@myhost.com>
        250 Ok
        RCPT TO: <friend@myhost.com>
        250 Ok
        DATA
        354 Please start mail input.
        Test
        .
        250 Mail queued for delivery.

        On an open SMTP server the first would have worked fine. I have posted an attachment with the modified class. I would suggest you do the following:

        1. Find out if your web host has an SMTP server. If so ask if you are required to log on first.

        2. Find an open SMTP server. There are some still out there. Some require you to sign up and log on, others do not. You should be able to find one by doing a google search.

        3. This is I suppose the most obvious - but make sure you have entered at least one recipient into the class. Also ensure that when you use the add_recipient() method you enter only one email address at a time. As SMTP does not like multiple email addresses separated by commars.

          Write a Reply...