title: How to send to BCC address when using PHPMailer to format MIME message for Gmail API?
body: <p>I am using PHPMailer to build an email message. I am using PHPMailer only for MIME message formatting, not sending. </p>
  
  <p>I then extract the raw message from the PHPMailer object before passing it on to the Gmail API for processing.</p>
  
  <pre><code>//Create a new PHPMailer instance
  $mail = new PHPMailer;
  
  //Tell PHPMailer to use SMTP
  $mail-&gt;isSMTP();
  $mail-&gt;IsHTML(true);
  
  //Disable SMTP debugging
  // 0 = off (for production use)
  $mail-&gt;SMTPDebug = 0;
  
  //Set who the message is to be sent from
  $mail-&gt;setFrom("fromaddress@domain.com", "From Name");
  
  //Set an alternative reply-to address
  $mail-&gt;addReplyTo("replyaddress@domain.com", "Reply Name");
  
  //Set to address
  $mail-&gt;addAddress("address@domain.com", "Some Name");
  
  //Set CC address
  $mail-&gt;addCC("ccaddress@ccdomain.com", "Some CC Name");
  
  //Set BCC address
  $mail-&gt;addBCC("bccaddress@ccdomain.com", "Some BCC Name");
  
  //Set the subject line
  $mail-&gt;Subject = "Test message";
  
  //Set the body
  $mail-&gt;Body = file_get_contents("/messagestore/some.html");
  
  //Attach a file
  $mail-&gt;addAttachment("/messagestore/some.pdf","some.pdf","base64","application/pdf");
  
  //generate mime message
  $mail-&gt;preSend();
  
  //get the mime text
  $mime = $mail-&gt;getSentMIMEMessage();
  
  //do the google API dance
  $newMailMessage = new Google_Service_Gmail_Message();
  $data = base64_encode($mime);
  $data = str_replace(array('+','/','='),array('-','_',''),$data); // url safe
  $newMailMessage-&gt;setRaw($data);
  $gmailService = new Google_Service_Gmail($google_client);
  $gmailService-&gt;users_messages-&gt;send('me', $newMailMessage);
  </code></pre>
  
  <p>According to PHPMailer docs, CC and BCC only function for sending in the Win32 environment. </p>
  
  <p>However, my MIME formatted messages transmit successfully via the Gmail API to the "TO" and "CC" addresses, but not the "BCC" address. </p>
  
  <p>To summarize, When I send email using <strong>this code</strong> and I provide a 'BCC' address to the Gmail API, I <strong><em>do not</em></strong> see 'undisclosed-recipients' in the sent message header, and the message <strong><em>is not</em></strong> transmitted to the BCC address. </p>
  
  <p>When I send email using <strong>the gmail web interface</strong> and I provide a 'BCC' address there, I <strong><em>do</em></strong> see 'undisclosed-recipients' in the sent message header, and the message <strong><em>is</em></strong> transmitted to the BCC address.</p>
  
  <p>Does anyone know of a workaround for this issue?</p>