简体   繁体   English

梨 PHP 邮件发送 CC 似乎不起作用

[英]Pear PHP Mail sending CC doesn't seem to work

I'm using PEAR's mail library via SMTP on my server and whilst I can get emails to generate, adding CC's doesn't seem to work.我在我的服务器上通过 SMTP 使用PEAR 的邮件库,虽然我可以生成电子邮件,但添加 CC 似乎不起作用。 Basically the CC recipients never get their email even though the main recipient of the same email does.基本上,CC 收件人永远不会得到他们的 email,即使同一 email 的主要收件人也有。

My basic setup is as follows, all the recipient variables ($to,$cc,$bcc) are string variables containing either a single recipient email addresses or comma separated email addresses.我的基本设置如下,所有收件人变量($to、$cc、$bcc)都是字符串变量,包含单个收件人 email 地址或逗号分隔的 email 地址。

    $headers = array (
        'From' => $from,
        'To' => $to,
        'Cc' => $cc,
        'Bcc' => $bcc,
        'Subject' => $subject,
        'Reply-To' => $from,
        'X-Mailer' => 'PHP/' . phpversion(),
        'MIME-Version' => '1.0',
        'Content-Type' => 'text/html; charset=ISO-8859-1'
    );
    $smtp = Mail::factory('smtp', array (
        'host' => $host,
        'port' => $port,
        'auth' => true,
        'username' => $username,
        'password' => $password
    ));

    $result = $smtp->send($to, $headers, $message);

I've read that sending BCCs is more complex, so lets stick to the CCs... why aren't they being received?我读过发送密件抄送更复杂,所以让我们坚持抄送……为什么没有收到? Is there anything obvious that I'm doing wrong here?有什么明显的地方我做错了吗?

In order to send an email to CC or BCC with SMTP, you must list all email addresses both under recipients to the send() function and in the CC key within the header. In order to send an email to CC or BCC with SMTP, you must list all email addresses both under recipients to the send() function and in the CC key within the header.

$to = "john@example.com";
$cc = "doe@example.com";
$recipients = $to . ", " . $cc;

$headers["From"] = "john@example.com";
$headers["To"] = $to;
$headers["Subject"] = "Hello World!";
$headers["Cc"] = "doe@example.com";
$headers["Reply-To"] = "john@example.com";

$send = $mail->send($recipients, $headers, $body);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM