use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; $mail = new PHPMailer(true); try { $mail->setFrom('from@example.com', 'My Name'); $mail->addAddress('to@example.com', 'Recipient Name'); $mail->addCC('cc@example.com', 'CC Recipient Name'); $mail->Subject = 'Test Email'; $mail->Body = 'Hello World!'; $mail->send(); echo 'Email has been sent'; } catch (Exception $e) { echo 'Email could not be sent. Error: ', $mail->ErrorInfo; }
use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; $mail = new PHPMailer(true); try { $mail->setFrom('from@example.com', 'My Name'); $mail->addAddress('to@example.com', 'Recipient Name'); $mail->addCC('cc1@example.com', 'CC Recipient 1 Name'); $mail->addCC('cc2@example.com', 'CC Recipient 2 Name'); $mail->Subject = 'Test Email'; $mail->Body = 'Hello World!'; $mail->send(); echo 'Email has been sent'; } catch (Exception $e) { echo 'Email could not be sent. Error: ', $mail->ErrorInfo; }In both examples, we used the PHPMailer library to send emails with CC recipients. The AddCC() method was used to add CC recipients to the email. The PHPMailer library can be found at https://github.com/PHPMailer/PHPMailer.