pear mail function bcc won't send

旧街凉风 提交于 2020-01-03 17:08:41

问题


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 = '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!");
}
?>

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!


回答1:


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

see the link below for pear mail

Sending multiple CC's and BCCs with PHP PEAR MAIL

or can get help from

http://phpmailer.worxware.com/index.php?pg=exampledb -- it is not pear mail. but it works very fine. I have used this and it is very easy to integrate.




回答2:


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 = "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);



回答3:


For those who are looking to the solution to adding cc and bcc in PEAR php mail. Here is the simple solution and the abbreviated explanation why.

ANSWER: Everyone who want to receive the mail must be added to the $recipients field. If they are not in this field, they will not get the mail. Everything you want to be visible, add to the header. Therefore, since bcc is BLIND carbon copy, do NOT add it to the header.

WHY?: The recipient field dictates where the mail goes, the headers dictate what is displayed. If you do not add cc to the header, then you can make them blind too. Whichever tickles your fancy. Any questions, check the link ripa added above! Great explanation!



来源:https://stackoverflow.com/questions/14557677/pear-mail-function-bcc-wont-send

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!