PHP脚本:使用SMTP发送到另一个电子邮件地址

Currently I am using the following script. This script will send an email to email1, but not always.

When somebody adds the second email2, the email only goes to number 2.

I want to change the script to sent to both emails (1 and 2) when email2 exists.

Tried a lot of things, but can't get it right.

// Email

if(!$row->email2){
        $email = $row->email1;
    } else{
        $email = $row->email2;

// Tried this below and a lot more

if(!$row->email2){
        $email = $row->email1;
    } else{
        $email = $row->email1;
        $email = $row->email2;

// E-mail to

if(!is_array($email)){
        $mail->ClearAddresses();
        $mail->AddAddress($email);
        $mail->Send();
    } else{
        foreach($email as $email){
            $mail->ClearAddresses();
            $mail->AddAddress($email);
            $mail->Send();
$emails = array();

if($email = $row->email1) {
    $emails[] = $email;
}

if($email = $row->email2) {
    $emails[] = $email;
}

foreach($email as $email){
    $mail->ClearAddresses();
    $mail->AddAddress($email);
    $mail->Send();
}