I copied a code for PEAR mail from a website, and input my data. It works. It sends mail, however, I want to use bcc to send to a lot of people and keep their addresses anonymous, and it will send to the $to recipients, but not the $bcc.
The code:
<?php
$message = "yay email!";
require_once("Mail.php");
$from = '[email protected] ';
$to = "[email protected]";
$bcc = "[email protected]";
$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!");
}
?>
P.s. I read on anther forum that I shouldn't put the headers in an array? I'm having trouble grasping the concept of the headers. What do they do and how should I organize them? I just want a to, from, subject, and bcc.
Thanks!
To elaborate on Chaky31's answer to send a Bcc
use the following, note that we do NOT specify any Bcc information in the header:
//All other variables should be self explanatory!
//The main recipient
$to = "[email protected]";
//Bcc recipients
$bcc = "[email protected]";
$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);