문제

I have a PHP script and I want to send messages via the bcc attribute. But this PHP script sends the message but does not send as bcc. The bcc addresses appear in the email message.

  // Construct the email
  $recipient = 'me@mydomain.com';

  $headers = array();
  $headers['From']        = 'ME <me@mydomain.com>';
  $headers['Subject']     = $subject;
  $headers['Reply-To']    = 'no-reply@mydomain.com';
  $headers['Bcc']         = 'abc@anotherdomain.com, xyz@thatdomain.com';
  $headers['Return-Path'] = 'me@mydomain.com';
  //$params['sendmail_args'] = '-fme@mydomain.com'; // this does not work

  $body = 'message body';

  // Define SMTP Parameters
  $params = array();
  $params['host']     = 'mail.mydomain.com';
  $params['port']     = '25';
  $params['auth']     = 'LOGIN';
  $params['username'] = 'me@mydomain.com'; // this needs to be a legitimate mail account on the server and not an alias
  $params['password'] = 'abcdef';

  // Create the mail object using the Mail::factory method
  include_once('Mail.php');
  $mail_object =& Mail::factory('smtp', $params);

  // Send the message
  $mail_object->send($recipient, $headers, $body);
도움이 되었습니까?

해결책

Here's something that I found: "If the Cc or Bcc lines appear in the message body, make sure you're separating header lines with a new line (\n) rather than a carriage return-new line (\r\n). That should come at the very end of the headers."

You might also want to try moving that header before or after others to see if it fixes things.

An even better solution would be to switch to phpMailer, which is supposedly a much, much better solution for sending mail through php.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top