problems with bcc email using php mailer
Results 1 to 7 of 7

Thread: problems with bcc email using php mailer

  1. #1
    Member
    Join Date
    Aug 2010
    Posts
    86

    problems with bcc email using php mailer

    Hi I'm trying to get this mail function to work, I'm using php mailer. I works just fine sending out the email but it doesn't seem to send the bcc emails, does anyone have any ideas why (I'm using fictional emails below). Any help would be really appreciated.

    PHP Code:

    // Purchase email configuration
    $email_subject="Your Course Details";
    $support_email_address="somebody@somwhere.com";
    $support_bcc="anybody@anywhere.com";
    $suppot_bcc.=",nobody@nowhere.com"

  2. #2
    Senior Member
    Join Date
    Oct 2005
    Location
    Chicago, IL
    Posts
    416
    Are you using the php mail() function or actually using PHPMailer?

    From what you posted it looks like the mail() function..

    If you are using PHPMailer to add bcc you would do something like

    PHP Code:
    $mailer->AddBCC('recipient1@domain.com''First Person');
    $mailer->AddBCC('recipient2@domain.com''Second Person');
    $mailer->AddBCC('recipient3@domain.com''Third Person'); 

    if you're using mail() your header will need the bcc:

    PHP Code:
    $headers .= 'Cc: test1@test1.com' "\r\n";
    $headers .= 'Bcc: test2@test2.com' "\r\n"
    Can you display more code? in particular your mail header(s)
    Bob Lob Law

  3. #3
    Member
    Join Date
    Aug 2010
    Posts
    86
    This is the mail function; that's called

    PHP Code:



    function mailmessage_nonsmtp($to$subject$body$format$fromaddress$bcc) {


        
    //Headers are separated by $sep (It may be necessary to use \n on some servers, but this not actually correct)
        
    $sep "\r\n";        //separater for headers

        

        //subject must not have newline character and make max length of 70 characters
        //body - each line should be separated with a LF (\n). Lines should not be larger than 70 characters. 

        //replace any \r\n, \n or \r with a space in subject line and only use 70 characters
        
    $subject str_replace("\r\n"" "$subject);
        
    $subject str_replace("\n"" "$subject);
        
    $subject str_replace("\r"" "$subject);
        
    //$subject = substr ( $subject, 0, 70 );

        //replace any \r\n with \n and use wordwrap() to split the lines which will use \n for new line
        //$body = str_replace("\r\n", "\n", $body);
        //$body = wordwrap($body, 70, "\n");
        
    $body WrapText($body70"\n"false);

        
    //construct the header
        
    $headers "";

        if ( 
    $format == "html" ) {  //To send HTML mail, you can set the Content-type header.
            
    $headers .= "MIME-Version: 1.0" $sep;
            
    $headers .= "Content-type: text/html; charset=iso-8859-1" $sep;
            
            
    //Mod added to convert double quote marks to the html equivilant
            
    $body str_replace('"''"'$body);
            
    //Mod added to convert single quote marks to the html equivilant        
            
    $body str_replace("'""'"$body);        
        }

        
    $headers .= "From:" $fromaddress $sep;

        if ( 
    $bcc != "" ) {
            
    $headers .= "Bcc:" $bcc $sep;
        }


        


        
    // Check for safe mode
        
    if( ini_get('safe_mode') ){        //safe mode on
            
    mail($to$subject$body$headers);    //Send with header.  
        
    }else{                            //safe mode off
            //Mod to overcome problem with some ISP not liking a Return-Path of root or nobody
            //If safe mode is on, the the fifth parameter is disabled so may have to use the above line instead.            
            
    $addparam "-f".$fromaddress;
            
    mail($to$subject$body$headers$addparam);    //Send with header
            
        
    }



    }
    function 
    WrapText($message$length$LE$qp_mode false) {
        
    $soft_break = ($qp_mode) ? sprintf(" =%s"$LE) : $LE;

        
    $message FixEOL($message$LE);
            if (
    substr($message, -1) == $LE)
                
    $message substr($message0, -1);

            
    $line explode($LE$message);
            
    $message "";
            for (
    $i=;$i count($line); $i++)
            {
              
    $line_part explode(" "$line[$i]);
              
    $buf "";
              for (
    $e 0$e<count($line_part); $e++)
              {
                  
    $word $line_part[$e];
                  if (
    $qp_mode and (strlen($word) > $length))
                  {
                    
    $space_left $length strlen($buf) - 1;
                    if (
    $e != 0)
                    {
                        if (
    $space_left 20)
                        {
                            
    $len $space_left;
                            if (
    substr($word$len 11) == "=")
                              
    $len--;
                            elseif (
    substr($word$len 21) == "=")
                              
    $len -= 2;
                            
    $part substr($word0$len);
                            
    $word substr($word$len);
                            
    $buf .= " " $part;
                            
    $message .= $buf sprintf("=%s"$LE);
                        }
                        else
                        {
                            
    $message .= $buf $soft_break;
                        }
                        
    $buf "";
                    }
                    while (
    strlen($word) > 0)
                    {
                        
    $len $length;
                        if (
    substr($word$len 11) == "=")
                            
    $len--;
                        elseif (
    substr($word$len 21) == "=")
                            
    $len -= 2;
                        
    $part substr($word0$len);
                        
    $word substr($word$len);

                        if (
    strlen($word) > 0)
                            
    $message .= $part sprintf("=%s"$LE);
                        else
                            
    $buf $part;
                    }
                  }
                  else
                  {
                    
    $buf_o $buf;
                    
    $buf .= ($e == 0) ? $word : (" " $word); 

                    if (
    strlen($buf) > $length and $buf_o != "")
                    {
                        
    $message .= $buf_o $soft_break;
                        
    $buf $word;
                    }
                  }
              }
              
    $message .= $buf $LE;
            }

            return 
    $message;
    }
        

    //-----------------------------------------------------------------
    /**
    * Purpose : Changes every end of line from CR or LF to CRLF. 
    * $LE is line ending characer which is normally '\n'
    * @return string
    */
    function FixEOL($str$LE) {
        
    $str str_replace("\r\n""\n"$str);
        
    $str str_replace("\r""\n"$str);
        
    $str str_replace("\n"$LE$str);
        return 
    $str;

    and this is the email that's sent out:

    PHP Code:

     
    if($course=="Online Anaphylasis Course")
          {
          
    $login=$login1;   //logins to take the course1
          
    $password=$password1;
          }
          else
          {
          
    $login=$login2;   //logins to take the course2
          
    $password=$password2;
          }
          
         
    //=================Edit Email body======================================================
      
    $body="Dear ".$fname." ".$lname.",<br> Thank you for purchasing our : " $course " we hope you enjoy it.<br>";
      
    $body .="To access your course details use the following information :<br><br>";
      
    $body .="If you go to the course web site : " .$courseweb"<br>";
      
    $body .="Login by : " .$login"<br>";
      
    $body .="The password is: " .$password"<br><br>";
      
    $body .= "This purchase allows you to complete the course once, course completions are monitored by our office and once you have pressed print for your certificate we are informed of your completion. Further course accesses will be charged for. If you have any problems in printing your certificate please contact our office and we will be able to supply you with one.
    <p>Any problems just let us know using the contact details below:<br>Tel: 0845 423 8993 or email:  
    <a href='mailto:coordinator@ecgtraining.co.uk'>ecgtraining.co.uk</a></p>"
    ;

              
      
    mailmessage_nonsmtp($payer_email$email_subject$body"html"$support_email_address$support_bcc); 

  4. #4
    Senior Member
    Join Date
    Aug 2008
    Location
    London, UK
    Posts
    753
    Each header (in $headers) should have a "\r\n" at the end to conform with email specifications. Try adding those to every line in your $headers string, i.e. at the end of the From, each Bcc, etc.
    Ashley Sheridan
    www.ashleysheridan.co.uk

  5. #5
    Senior Member Derokorian's Avatar
    Join Date
    Apr 2011
    Location
    Denver
    Posts
    1,740
    Quote Originally Posted by Ashley Sheridan View Post
    Each header (in $headers) should have a "\r\n" at the end to conform with email specifications. Try adding those to every line in your $headers string, i.e. at the end of the From, each Bcc, etc.
    That's what the $sep variable is doing at the end of each of his headers. One thing I notice is in your first post you have:
    PHP Code:
    $support_bcc="anybody@anywhere.com"
    $suppot_bcc.=",nobody@nowhere.com"
    Which means it will never go to nobody@nowhere.com because there is a typo in the variable name.
    Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail
    I'd rather be a comma, then a full stop.
    User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning

  6. #6
    Senior Member
    Join Date
    Oct 2005
    Location
    Chicago, IL
    Posts
    416
    he is using '\r\n'. He's concatenating w/ his $sep variable.


    what is the value of your $bcc variable. can you print_r() that out and post?


    if it's what you originally posted:

    PHP Code:
    // Purchase email configuration 
    $email_subject="Your Course Details"
    $support_email_address="somebody@somwhere.com"
    $support_bcc="anybody@anywhere.com"
    $suppot_bcc.=",nobody@nowhere.com"
    You're missing the 'r' in $support on your the second bcc variable you're attempting to concatenate.
    Bob Lob Law

  7. #7
    Senior Member
    Join Date
    Oct 2005
    Location
    Chicago, IL
    Posts
    416
    Derokorian beat me to the reply....
    Bob Lob Law

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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