Bcc mail function does not send

I copied the code for PEAR mail from the website and entered my details. It works. It sends mail, however I want to use bcc to send to many people and keep their anonymous addresses and it will send addresses to recipients $ but not $ bcc.

Code:

<?php
$message = "yay email!";
require_once("Mail.php");
$from = 'myaddress@mysite.com ';
$to = "anadress@gmail.com";
$bcc = "thepeopleimemailing@yaddayadda.com";
$subject = " test";
$body = $message;
$host = "smtp.mysite.com";
$username = "myusername";
$password = "mypassword";
$headers = array ('From' => $from,
    'To' => $to,
    'Cc' => $cc,
    'Bcc' => $bcc,
    'Subject' => $subject
);
$recipients = $to;


$smtp = Mail::factory('smtp',
    array ('host' => $host,
        'auth' => true,
        'username' => $username,
        'password' => $password,
        'port' => '25'
    )
);
$mail = $smtp->send($recipients, $headers, $body);
if (PEAR::isError($mail)) {
    echo($mail->getMessage());
}
else {
    echo("Message successfully sent!");
}
?>

      

Ps I read on the forum that I shouldn't put headers in an array? I'm having trouble understanding headers. What do they do and how do you organize them? I just want to, from, themes and bcc.

Thank!

+3


source to share


3 answers


use $headers['Cc'] = 'cc@example.com, bb@example.com, dd@ex.com';

see link below for pear post

Sending multiple CCs and BCCs with PHP PEAR MAIL



or can get help from

http://phpmailer.worxware.com/index.php?pg=exampledb is not a bag of mail. but it works really well. I have used this and it is very easy to integrate.

+1


source


To elaborate on Chaky31's answer to submit Bcc

, use the following, please note that we are NOT listing any Bcc information in the header:



//All other variables should be self explanatory!

//The main recipient
$to = "test@test.com";

//Bcc recipients
$bcc = "bcc@test.com";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'port' => $port,
    'auth' => true,
    'username' => $username,
    'password' => $password));

//We append the bcc addresses as comma seperated values to the send method
$mail = $smtp->send($to . "," . $bcc, $headers, $body);

      

+6


source


For anyone looking for a solution to add cc and bcc to PEAR mail. Here's a simple solution and a short explanation of why.

ANSWER: Anyone who wants to receive mail must be added to the field $recipients

. If they are not in this field, they will not receive mail. Anything you want to see add to the title. Therefore, since bcc is a copy of BLIND, do not add it to the header.

WHY: The recipient field determines where the mail goes, the headers determine what is displayed. If you don't add cc to the title, you can make them blind as well. Whatever the tickle of your fantasy. Any questions, check the ripa link added above! Great explanation!

+2


source







All Articles