Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BCCs are not being sent. #2758

Closed
dqhendricks opened this issue Aug 25, 2022 · 3 comments
Closed

BCCs are not being sent. #2758

dqhendricks opened this issue Aug 25, 2022 · 3 comments

Comments

@dqhendricks
Copy link

Description

I have set up PHPMailer and can send emails successfully. When I use addBCC( $address ) or addCustomHeader( 'BCC', $address ) however, nothing gets sent to the BCC address. The message still reaches the To address. I am using a linux server, with PHP 5.6.

Code to reproduce

Using SMTP and HTML:

$mail->addBCC( '[email protected]' );

OR

$mail->addCustomHeader( 'BCC', '[email protected]' );

Debug output

No errors or debug output.

@XL-2000
Copy link

XL-2000 commented Aug 26, 2022

So many questions....
Which version of PHPMailer are you using?
Did you check compatibility between PHP and PHPMailer?
Why in the worlds name are you using an ancient PHP version? You should absolutely upgrade!
Why are you using "addCustomHeader" to add a BCC header? This is absolutely WRONG...
Where is the rest of your code?
What does the log or debug say?

@dqhendricks
Copy link
Author

dqhendricks commented Aug 26, 2022

@XL-2000

  • I am using the latest version of PHPMailer-master downloaded yesterday.
  • I read on this repository that this version is supposed to be compatible with "PHP 5.5 and later". Is there something else I should check to see if it is compatible?
  • I am using 5.6 due to some legacy code on the same server. I wish I could upgrade.
  • addCustomerHeader() was a suggestion from stackoverflow, where someone claimed addBCC() only works for Win32 SMTP, and that they had to use a work around using addCustomHeader() to get BCC to work with PHPMailer. I tried both and neither worked however.
  • There were no errors or debug info. The mail sent. Just no BCCs added.
  • Here's my code. It's pretty much copy paste from this repository's examples. $bcc is an array of plain email addresses and I verified that the addBCC() is in fact being reached when the code runs with a proper address.
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require_once 'PHPMailer-master/src/Exception.php';
require_once 'PHPMailer-master/src/PHPMailer.php';
require_once 'PHPMailer-master/src/SMTP.php';

class EmailManager {
	protected $from_email = '[email protected]';
	protected $from_password = '[mypassword]';
	protected $from_name = 'Writing Group App';
	
	function emailHTML( $to, $subject, $message, $reply_to = null, $bcc = null ) {
		$this->email( true, $to, $subject, $message, $reply_to, $bcc );
	}
	
	function emailText( $to, $subject, $message, $reply_to = null, $bcc = null ) {
		$this->email( false, $to, $subject, $message, $reply_to, $bcc );
	}
	
	function email( $isHTML, $to, $subject, $message, $reply_to = null, $bcc = null ) {
		try {
			// server settings
			$mail = new PHPMailer( true );
			$mail->isSMTP();
			$mail->Host = 'writinggroupapp.com';
			$mail->SMTPAuth = true;
			$mail->Username = $this->from_email;
			$mail->Password = $this->from_password;
			$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
			$mail->Port = 465;
			// to/from settings
			$mail->setFrom( $this->from_email, $this->from_name );
			$mail->addAddress( $to );
			if ( $reply_to ) $mail->addReplyTo( $reply_to );
			//if ( $bcc ) $mail->addCustomHeader( 'BCC', implode( ',', $bcc ) ); // work around doesn't seem to work either
			if ( $bcc ) {
				foreach ( $bcc as $address ) {
					$mail->addBCC( $address ); // apparently only works on win32 mail servers?
				}
			}
			// attachments
			//$mail->addAttachment('/var/tmp/file.tar.gz');
			// content
			if ( $isHTML ) $mail->isHTML( true );
			$mail->Subject = $subject;
			$mail->Body = $message;
			if ( $isHTML ) $mail->AltBody = strip_tags( $message );
			// send
			$mail->send();
		} catch ( Exception $e ) {
			echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
		}
	}
}

@dqhendricks
Copy link
Author

Seems to be an issue with the mail server and not PHPMailer. Sorry for the trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants