isSMTP(); $mail->Host = "smtp.gmail.com"; $mail->SMTPAuth = true; // $mail->Username = "sascpone@gmail.com"; // $mail->Password = "ahpn zkcw ymkg hsij"; $mail->Username = $username; $mail->Password = $password; $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->Post = 587; $mail->setFrom($sender["email"], $sender["name"]); foreach ($recipients as $rec) { $mail->addAddress($rec["email"], $rec["name"]); } foreach ($cc as $rec) { $mail->addCC($rec["email"], $rec["name"]); } $mail->isHTML($isHtml); $mail->Subject = $subject; $mail->Body = $message; if (count($attachment) > 0) { $arr_tmp = []; for ($i_att = 0; $i_att < count($attachment); $i_att++) { $tmpName = tempnam("/tmp", "att-"); $fname = $attachment[$i_att]["name"]; $url = $attachment[$i_att]["url"]; if ($tmpName === false) { return [false, "Failed Create tmpFile for $fname"]; } $tmp_data = file_get_contents($url); $status = file_put_contents($tmpName, $tmp_data); if ($status === false) { return [false, "Failed Create tmpFile for $fname put"]; } $arr_tmp[] = $tmpName; $mail->addAttachment($tmpName, $fname); } } if (!$mail->send()) { $mail->smtpClose(); foreach ($arr_tmp as $tmpName) { unlink($tmpName); } return [false, $mail->ErrorInfo]; } else { $mail->smtpClose(); foreach ($arr_tmp as $tmpName) { unlink($tmpName); } return [true, ""]; } } }