I have problem sending multiple email cc separated by coma symbol using PHPMailer . . i'm using PHP 7.
I have these data in my mysql database contains multiple email address in single user account separated by coma (,) .
I already follow the answer from this question here, but its not working. email can only be sent to john@mail.com . billy@mail.com did not receive any mail.
I tried to echo var_dump(maildbs);
output shown without coma . .
john@mail.combilly@mail.com
Here's my PHP code . .
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>
Appreciate if someone can help.