SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    619
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    send 2 emails with different replyto

    hi all

    i am sending email with php mail().

    i m using the following headers
    PHP Code:
    $to$log_id;
    $subject"welcome to company";
    $headers  'MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
    $headers .= 'From:info@domain.com' "\r\n";
    $headers .= "CC:info@domain.com" "\r\n";
    $headers .= "Reply-To:".$log_id "\r\n";
    $headers .= "Return-Path:".$log_id "\r\n";
                
    $body=" ";
    if(
    mail($to,$subject,$body,$headers))
    {
        
    $msg="email processed";;
    }
    else
    {
        
    $msg="order not processed";

    This email function works fine and email is sent successfully.

    Now i want to send one more email with Different "Reply to" address and rest all remains same.

    As the $body test is lengthy, so i want to ask that instead of writing two separate full emails code,
    is there anyother way i can sent two emails simultaneously without repeating my $body code but with different "Reply-To" addresses.

    vineet

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,901
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    PHP Code:
    $body=" ";
    $mailSentOk true;
    $to$log_id;
    $subject"welcome to company";

    foreach(array(
    'someone@somedomain.com','someoneelese@somedomain.com') as $reply_to)
    {
      
    $headers  'MIME-Version: 1.0' "\r\n";
      
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
      
    $headers .= 'From:info@domain.com' "\r\n";
      
    $headers .= "CC:info@domain.com" "\r\n";
      
    $headers .= "Reply-To:".$reply_to "\r\n";
      
    $headers .= "Return-Path:".$log_id"\r\n";
      
      
    $mailSentOk $mailSentOk && mail($to,$subject,$body,$headers);
    }
    if(
    $mailSentOk)
    {
        
    $msg="email processed";;
    }
    else
    {
        
    $msg="order not processed";

    Also, please note that mail returns whether the mail was succesfully
    sent, not whether it was succesfully received!

    And since the headers change you can't get them outside of the foreach.
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    619
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thanks scallioXTX

    it works fine now.

    vineet

    Quote Originally Posted by ScallioXTX View Post
    PHP Code:
    $body=" ";
    $mailSentOk true;
    $to$log_id;
    $subject"welcome to company";

    foreach(array(
    'someone@somedomain.com','someoneelese@somedomain.com') as $reply_to)
    {
      
    $headers  'MIME-Version: 1.0' "\r\n";
      
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
      
    $headers .= 'From:info@domain.com' "\r\n";
      
    $headers .= "CC:info@domain.com" "\r\n";
      
    $headers .= "Reply-To:".$reply_to "\r\n";
      
    $headers .= "Return-Path:".$log_id"\r\n";
      
      
    $mailSentOk $mailSentOk && mail($to,$subject,$body,$headers);
    }
    if(
    $mailSentOk)
    {
        
    $msg="email processed";;
    }
    else
    {
        
    $msg="order not processed";

    Also, please note that mail returns whether the mail was succesfully
    sent, not whether it was succesfully received!

    And since the headers change you can't get them outside of the foreach.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •