0

I am using phpmailer doing send multiple email address functions to recepients. Now my problem is, I cannot send all selected multiple addresses, just can send 1 address to the recipient.

Below is my code:

$checkbox_value = '"st9overfindsolution@gmail.com" => "Admin","st7overfindsolution@gmail.com" => "EZLIN EDZRINA BT MEOR KAMARUDDIN","baby@gmail.com" => "IZUARINI BT MAHMAD SANI"';
$recipients = $checkbox_value;
require 'plugins/mail/class.phpmailer.php';
$mail = new PHPMailer(true);
$mail->IsSMTP();                                //Sets Mailer to send message using SMTP
$mail->Host = 'smtp.gmail.com';     //Sets the SMTP hosts of your Email hosting, this for Godaddy
$mail->SMTPDebug = 0;
$mail->Port = 465;                              //Sets the default SMTP server port
$mail->SMTPAuth = true;                         //Sets SMTP authentication. Utilizes the Username and Password variables
$mail->Username = 'asf1n@gmail.com';                    //Sets SMTP username
$mail->Password = 'gdsA215';                    //Sets SMTP password
$mail->SMTPSecure = 'ssl';                      //Sets connection prefix. Options are "", "ssl" or "tls"
$mail->From = "aa";                 //Sets the From email address for the message
$mail->FromName = "aaa";                //Sets the From name of the message
foreach ($recipients as $email => $name) {
$mail->AddAddress($email, $name); 
} 
// $mail->AddAddress('dsgas@gmail.com', 'Ong');     //Adds a "To" address
$mail->AddCC("aaa@gmail.com", "sagsa"); //Adds a "Cc" address
$mail->WordWrap = 50;                           //Sets word wrapping on the body of the message to a given number of characters
$mail->IsHTML(true);                            //Sets message type to HTML             
$mail->Subject = $tajuk_email;              //Sets the Subject of the message
$mail->Body = $kandungan_email;             //An HTML or plain text message body

For above coding result, I just can send email to st9overfindsolution@gmail.com, other recipient cannot receive email. Is any wrong for my coding? Hope someone can guide me on how to solve the problem. I think below the coding got something error:

$checkbox_value = '"st9overfindsolution@gmail.com" => "Admin","st7overfindsolution@gmail.com" => "EZLIN EDZRINA BT MEOR KAMARUDDIN","baby@gmail.com" => "IZUARINI BT MAHMAD SANI"';
$recipients = $checkbox_value;
foreach ($recipients as $email => $name) {
$mail->AddAddress($email, $name); 
}
Fatt Sky
  • 650
  • 3
  • 11
  • `$recipients` is a string, which is the same as you wanted to strip apart your [previous](https://stackoverflow.com/questions/68265500/put-the-variable-in-the-php-array) question. Try and solve that part and then pass that as the array. – Nigel Ren Jul 07 '21 at 07:24
  • Yes. I am not sure how to pass the variable data to the array. – Fatt Sky Jul 07 '21 at 07:25
  • A quick 'fudge' - `$checkbox_value = str_replace("=>", ":", $checkbox_value); $checkboxes = json_decode( "{" . $checkbox_value . "}", true);` – Nigel Ren Jul 07 '21 at 07:29
  • Ok. So the $checkbox_value put in the array right? ` $checkbox_value = str_replace("=>", ":", $checkbox_value); $checkboxes = json_decode( "{" . $checkbox_value . "}", true); $checkbox_value = '"st9overfindsolution@gmail.com" => "Admin","st7overfindsolution@gmail.com" => "EZLIN EDZRINA BT MEOR KAMARUDDIN","baby@gmail.com" => "IZUARINI BT MAHMAD SANI"'; $recipients = $checkbox_value; foreach ($recipients as $email => $name) { $mail->AddAddress($email, $name); }` – Fatt Sky Jul 07 '21 at 07:35
  • Like this edit? – Fatt Sky Jul 07 '21 at 07:35
  • You would put the code I mentioned after `$checkbox_value = '"st9o` and then use `foreach ($checkboxes as` – Nigel Ren Jul 07 '21 at 07:40
  • Ok. I try it. Thanks. – Fatt Sky Jul 07 '21 at 07:40

0 Answers0