加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – bcc与swiftmailer的多个地址

发布时间:2020-12-13 17:45:51 所属栏目:PHP教程 来源:网络整理
导读:我使用下面的 PHP代码发送电子邮件到一个地址和密送2其他地址.它向收件人发送罚款,但我只能将其发送到2个密件抄送地址之一. (请参阅代码中的注释,我尝试过) 奇怪的是,$结果回来了3所以它似乎试图发送第二封密送电子邮件,但它永远不会通过. ?php $tracker='tr
我使用下面的 PHP代码发送电子邮件到一个地址和密送2其他地址.它向收件人发送罚款,但我只能将其发送到2个密件抄送地址之一. (请参阅代码中的注释,我尝试过)

奇怪的是,$结果回来了3所以它似乎试图发送第二封密送电子邮件,但它永远不会通过.

<?php


    $tracker='tracking@pnrbuilder.com';
    $subject = $_POST['subject'];
    $sender = $_POST['sender'];
    $toEmail=$_POST['toEmail'];
    $passedInEmail=stripslashes($_POST['message']);
    $passedInEmail=preg_replace('/&nbsp;/',' ',$passedInEmail);

    require_once('swiftLib/simple_html_dom.php');
    require_once('swiftLib/swift_required.php');
    $transport = Swift_MailTransport::newInstance();
    $mailer = Swift_Mailer::newInstance($transport);
    // Create the message
    $message = Swift_Message::newInstance();
    //turn the meesage into an object using simple_html_dom
    //so we can iterate through and embed each image
    $content = str_get_html($passedInEmail);

    // Retrieve all img src tags and replace them with embedded images
    foreach($content->find('img') as $e) 
        {
            if($e->src != "") 
                {
                    $value = $e->src;
                    $newValue = $message->embed(Swift_Image::fromPath($value)); 
                    $e->src = $newValue;
                }
        }

    $message->setSubject($subject);
    $message->setFrom($sender);
    $message->setTo($toEmail);



    //this is my problem
    $message->setBcc(array('tracking@pnrbuilder.com',$sender));
    //as it is above only "sender" gets the email

    //if I change it like this:

    //$message->setBcc($tracker,$sender);
    //only "tracker" gets the email


    //same if I change it like this:
    //$message->setBcc($sender);
//$message->addBcc($tracker);

    $message->setReplyTo(array('flights@pnrbuilder.com'));
    $message->setBody($content,'text/html');


    $result = $mailer->send($message);
    if ($result=3) {
        echo 'Email Sent!';
    } 
    else {
       echo 'Error!';
    }
?>

这样做的正确方法是什么?

解决方法

你可以找到swiftmailer教程 here

例:

$message->setBcc(array(array('some@address.tld' => 'The Name'),array('another@address.tld' => 'Another Name')));

尝试设置电子邮件地址的名称,看看它是否有所不同.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读