[英]Phpmailer AddBcc not working
我正在使用 phpmailer 發送電子郵件,它可以讓收件人收到郵件,但密件抄送和抄送詳細信息未顯示郵件。 有人可以為此提出解決方案。 代碼是
require_once("PHPMailer_v5.1/class.phpmailer.php");
require_once("PHPMailer_v5.1/language/phpmailer.lang-en.php");
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->SMTPAuth = true;
$mailer->SMTPSecure = "tls";
$mailer->Host = 'smtp.gmail.com';
$mailer->Port = 587;
$mailer->Username = "myuserid";
$mailer->Password = "mypassword";
$mailer->FromName = $fromname;
$mailer->From = "myuserid";
$mailer->AddAddress("to@gmail.com",$toname);
$mailer->Subject = $subject;
$mailer->Body =$content;
$mailer->AddCC("something@gmail.com", "bla");
$mailer->AddBCC("foo@gmail.com", "test");
if(!$mailer->Send())
{
echo "Message was not sent";
}
else
echo "mail sent";
用於
$mailer->AddBCC("foo@gmail.com", "test");
$mailer->AddCC("something@gmail.com", "bla");
您永遠不會看到密件抄送詳細信息。 這就是它們的 BCC 詳細信息。 即使是 BCC 的收件人也不會在收件人中看到他自己的名字。
PS:你注意到你寫的是addBCC
而不是AddBCC
(大寫A
)?
來自 phpMailer 函數參考:
添加“密件抄送”地址。 注意:此功能適用於 win32 上的 SMTP 郵件程序,而不適用於“郵件”郵件程序。
這可能會導致您的問題。
老問題,但我最終在這里尋找答案。 剛剛在別處了解到這些函數 AddCC 和 AddBCC 僅適用於 win32 SMTP
嘗試使用:
$mail->addCustomHeader("密件抄送:mybccaddress@mydomain.com"); 請參閱http://phpmailer.worxware.com/?pg=methods
希望這對某人有所幫助,干杯!
它添加了BCC
$email->addBCC('my@email.com', 'My Name');
請參閱第 934 行的 PHPMailer.php(當前版本 6.0.5)( https://github.com/PHPMailer/PHPMailer/blob/master/src/PHPMailer.php#L934 ):
/**
* Add a "BCC" address.
*
* @param string $address The email address to send to
* @param string $name
*
* @return bool true on success, false if address already used or invalid in some way
*/
public function addBCC($address, $name = '')
{
return $this->addOrEnqueueAnAddress('bcc', $address, $name);
}
密件抄送永遠不會顯示; 只有 TO 和 CC
BCC=密件抄送
這是最新版本的一個工作示例,在 Office 365 上,我使用它從共享文件夾發送電子郵件...
<?
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once('./phpmailer/Exception.php');
require_once('./phpmailer/PHPMailer.php');
require_once('./phpmailer/SMTP.php');
//* Working Example As Of 09/21/2019 - Sends From Shared Mailbox With Mailbox Member
function SendO365EmailTLS($options)
{
$from = isset($options['from']) ? $options['from'] : false;
$recipients = isset($options['recipients']) ? $options['recipients'] : false;
$ccRecipeints = isset($options['ccrecipients']) ? $options['ccrecipients'] : [];
$bccRecipients = isset($options['bccrecipients']) ? $options['bccrecipients'] : [];
$attachments = isset($options['attachments']) ? $options['attachments'] : [];
$credentials = isset($options['credentials']) ? $options['credentials'] : false;
$subject = isset($options['subject']) ? $options['subject'] : '';
$body = isset($options['body']) ? $options['body'] : '';
if(!$from) throw new Exception('Cannot send email with blank \'from\' field');
if(!$recipients) throw new Exception('Cannot send email, no recipients specified!');
if(!$credentials) throw new Exception('Cannot send email, credentials not provided!');
$mail = new PHPMailer;
foreach($recipients as $recipient) $mail->addAddress( $recipient[ 'email'], $recipient['name']);
foreach($ccRecipeints as $ccRecipient) $mail->addCC( $ccRecipient[ 'email'], $ccRecipient['name']);
foreach($bccRecipients as $bccRecipient) $mail->addBCC( $bccRecipient['email'],$bccRecipient['name']);
foreach($attachments as $attachment) $mail->addAttachment($attachment[ 'path' ], $attachment['name']);
$mail->setFrom($from['email'], $from['name']);
$mail->Username = $credentials['username'];
$mail->Password = $credentials['password'];
$mail->Host = 'smtp.office365.com';
$mail->Subject = $subject;
$mail->SMTPSecure = 'tls';
$mail->Body = $body;
$mail->SMTPAuth = true;
$mail->isHTML(true);
$mail->Port = 587;
$mail->isSMTP();
$success = $mail->send();
return $success;
}
// $options = ['from'=> ['email'=>'', 'name'=>''],
// 'recipients'=> [['email'=>'', 'name'=>'']],
// 'ccrecipients'=> [['email'=>'', 'name'=>'']],
// 'bccrecipients'=>[['email'=>'', 'name'=>'']],
// 'attachments'=> [['path'=>'./attachments/file1.jpg','name'=>'1.jpg'],
// ['path'=>'./attachments/file2.jpg','name'=>'2.jpg'],
// ['path'=>'./attachments/file3.jpg','name'=>'3.jpg']],
// 'credentials'=> ['username'=>'','password'=>''],
// 'subject'=> 'Email Subject Line',
// 'body'=> '<h1>Email Body</h1><p>HTML!!!</p>'];
// $success = SendO365EmailTLS($options);
// echo $success ? 'Email Sent':'Email Not Sent';
// die();
$mail->addCC('cc@example.com');//Carbon copy $mail->addBCC('bcc@example.com');//Blind Carbon copy
要操作 clausla BCC AddCC 必須先於 nuloy 隱藏的電子郵件將到達您的收件人,否則會發生 nuna 示例:
$ mail-> AddCC ("");
$ mail-> AddBCC ("mail @ domain")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.