【问题标题】:PHPMailer sending multiple email cc address separated by coma symbolPHPMailer 发送多个电子邮件抄送地址,以逗号分隔
【发布时间】:2017-10-02 06:06:29
【问题描述】:

我在使用 PHPMailer 发送多个由逗号分隔的电子邮件 cc 时遇到问题。 .我正在使用 PHP 7。

我的 mysql 数据库中的这些数据包含单个用户帐户中的多个电子邮件地址,以逗号 (,) 分隔。

我已经关注了这个问题here 的答案,但它不起作用。电子邮件只能发送到 john@mail.com 。 billy@mail.com 没有收到任何邮件。

我尝试回显 var_dump(maildbs);

输出显示没有昏迷。 .

john@mail.combilly@mail.com

这是我的 PHP 代码。 .

sendmail.php

<?php
    $connect      = mysqli_connect("", "", "", "");
    global $connect;  
    if(isset($_POST['Submit'])){
        $staffname = $_POST['staffname'];
        $sql = "SELECT * FROM table WHERE staff_name ='$staffname'";
        $get = mysqli_query($connect,$sql);
        if($get && mysqli_num_rows($get) > 0 )
        {              
            while($row = mysqli_fetch_assoc($get))
            {
                $maildbs = explode(',',$row["email_address"]);
                foreach($maildbs as $maildb){
                    date_default_timezone_set('Etc/UTC');
                    require_once '../PHPMailerAutoload.php';
                    $mail = new PHPMailer;
                    $mail->isSMTP();
                    $mail->SMTPDebug = 2;
                    $mail->Debugoutput = 'html';
                    $mail->Host = "host";
                    $mail->Port = 25;
                    $mail->SMTPAuth = false;
                    $mail->setFrom('sender@mail.com', 'Sender');
                    $mail->addAddress('mail@mail.com','receipent');
                    $mail->addCC($maildb);
                    $mail->Subject = 'PHPMailer SMTP without auth test';
                    $mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
                    $mail->AltBody = 'This is a plain-text message body';
                    $mail->Body = 'body content';
                    $mail->addAttachment('images/phpmailer_mini.png');
                    if (!$mail->send()) {
                        echo "Mailer Error: " . $mail->ErrorInfo;
                    } else {
                        echo "Message sent!";
                    }                   
                }   
            }   
        mysqli_free_result($get);
        }
    }
?>
<!DOCTYPE html>
<html><title>Test Email</title></head>
<body>
    <table>
        <form action="sendmail.php" method="POST">
            <tr>
                <td>Staff Name :</td>
                <td><input type="text" name="staffname" value="" ></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" name="Submit" value="send email"></td>
            </tr>
        </form>
    </table>
</body>
</html>

感谢有人可以提供帮助。

【问题讨论】:

标签: php mysql email phpmailer


【解决方案1】:

使用explode php函数

             $email = explode(',', $toEmail);
                for ($i = 0; $i < count($email); $i++) {
                    $mail->addAddress($email[$i], 'recipient '); 
                }
                if ($ccEmail != null) {
                    $emailCC = explode(',', $ccEmail);
                    for ($i = 0; $i < count($emailCC); $i++) {
                        $mail->addCC($emailCC[$i]);
                    }
                }
                if ($ccBCC != null) {
                    $emailBCC = explode(',', $ccBCC);
                    for ($i = 0; $i < count($emailBCC); $i++) {
                        $mail->addBCC($emailBCC[$i]);
                    }
                }

【讨论】:

  • 好的。让我先试试。
猜你喜欢
  • 2011-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-29
  • 2021-09-13
  • 2014-06-27
  • 2013-08-15
  • 2021-12-15
相关资源
最近更新 更多