I want to make it so that the CC field is optional to have, but right now, the email only sends if there is a cc field, and if I don’t have a $CC value, it throws an error "Invalid address: cc"
$mail->addAddress($EmailTo);
$mail->addCC($CC);
$mail->Subject = $Subject;
$mail->Body = nl2br($Message);
$mail->AltBody = nl2br($Message);
$mail->isHTML(false);
$mail->send();
The email also sends if I remove any lines with $CC to just the one email, but I also tried to add this since I thought it’s throwing an error because the CC field was empty
if (isset($_POST['emailfrom'])) {
$mail->addCC($CC);
} else {
$mail->send();
}
2
Answers
solution: replaced $mail->addCC($CC); with
First line can be follows:
$mail->addAddress( '[email protected]', 'Mr. Main' );
Ur email direction must exists.
$toEmail = $value['email']; // '[email protected]'
$toName = $value['name']; // 'Mr. Testing'
$mail->addCC($toEmail, $toName);