如何在Sendgrid中批量发送邮件时添加密件抄送?

问题描述 投票:0回答:2

我正在使用 Sendgrid API 发送批量电子邮件,它运行得非常完美。现在,每当向 Sendgrid 请求发送批量电子邮件时,客户都希望密件抄送他的电子邮件。

这是我迄今为止尝试过的:

    $sendgrid = new SendGrid($user_sendgrid, $pass_sendgrid);
    $email = new SendGrid\Email();
    $email
        ->setSmtpapiTos($emails)
        ->setFrom(<Sender Email>)
        ->setSubject(' ')
        ->setText(' ')
        ->addBcc(<Bcc Email>)
        ->addSubstitution("[firstname]", $firstname)
        ->addSubstitution("[lastname]", $lastname)
        ->setHtml(' ');
    $sendgrid->send($email);

它会向用户发送电子邮件,但不会向密件抄送的人发送电子邮件。

php email sendgrid
2个回答
0
投票

如果您设置 SMTPAPI 收件人地址,则本机收件人/密件抄送/抄送地址将被删除。您需要在 SMTPAPI 字符串中设置 BCC 过滤器值

请注意,此密件抄送地址也使用 SendGrid 上的信用,因为您实际上使邮件量增加了一倍。


0
投票

如果您想密件抄送发件人本身,这是可能的。我的解决方案是在密件抄送上添加用户。我在这里使用 Sendgrid API ver 3 + Laravel:

    $email = "[email protected]";
    $subject = "Email Subject";
    $body = "Body of email";

    $bccUsers = array();
    $bccUsers[] = "[email protected]";
    $bccUsers[] = "[email protected]";
    $bccUsers[] = "[email protected]";

    $send = Mail::send('email.test', ['body' => $body],
        function($mail) use ($email, $subject, $bccUsers){
            $mail->from("[email protected]", "Email Sender")
                ->to($email)
                ->bcc($bccUsers)
                ->subject($subject);
        });
© www.soinside.com 2019 - 2024. All rights reserved.