Asked  1 Year ago    Answers:  4   Viewed   6 times

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:

$message = "yay email!";
$from = ' ';
$to = "";
$bcc = "";
$subject = " test";
$body = $message;
$host = "";
$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)) {
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.




use $headers['Cc'] = ',,';

see the link below for pear mail

Sending multiple CC's and BCCs with PHP PEAR MAIL

or can get help from -- it is not pear mail. but it works very fine. I have used this and it is very easy to integrate.

Thursday, April 1, 2021

You have $headers .= '...'; followed by $headers = '...';; the second line is overwriting the first.

Just put the $headers .= "Bcc: $emailListrn"; say after the Content-type line and it should be fine.

On a side note, the To is generally required; mail servers might mark your message as spam otherwise.

$headers  = "From:" .
  "X-Mailer: phprn";
$headers .= "MIME-Version: 1.0rn";
$headers .= "Content-Type: text/html; charset=ISO-8859-1rn";
$headers .= "Bcc: $emailListrn";
Thursday, April 1, 2021

Non-static method Mail::factory() should not be called statically

This is a non-fatal notice coming from PHP because PEAR Mail is prehistoric and hasn't been updated to use the static keyword introduced five years ago in PHP5.

After reviewing the documentation, your call to Mail::factory looks completely correct and normal.

You failed to tell us if if the call to send succeeds or fails. If it's succeeding, but the mail is never being delivered, please check the SMTP server logs. If it's failing, what's the actual error message? The Mail::send documentation includes a comprehensive list of errors.

You might want to consider using a more modern mail sending library, like Swiftmailer.

Thursday, April 1, 2021

Simplest solution if you don't mind encoding even words that don't need it is to put everything in a base64 RFC 2047 encoded-word:

$subject= "=?utf-8?b?".base64_encode($subject)."?=";
$body= "blah blah $utf8text blah";
$headers= "MIME-Version: 1.0rn";
$headers.= "From: =?utf-8?b?".base64_encode($fromname)."?= <$fromaddress>rn";
$headers.= "Content-Type: text/plain;charset=utf-8";

mail($toaddress, $subject, $body, $headers);
Thursday, August 19, 2021
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :