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.


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

    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

    $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:

    $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)

      This is the mail function; that's called

      
      
      
      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($body, 70, "\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($message, 0, -1);
      
          $line = explode($LE, $message);
          $message = "";
          for ($i=0 ;$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 - 1, 1) == "=")
                            $len--;
                          elseif (substr($word, $len - 2, 1) == "=")
                            $len -= 2;
                          $part = substr($word, 0, $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 - 1, 1) == "=")
                          $len--;
                      elseif (substr($word, $len - 2, 1) == "=")
                          $len -= 2;
                      $part = substr($word, 0, $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:

      
       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);

        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;11002035 wrote:

          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:

          $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.

            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:

            // 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.

              Write a Reply...