SMTPDebug = SMTP::DEBUG_SERVER; // enable verbose output $mail->Debugoutput = function($str){ $GLOBALS['debugOutput'] .= "$str
"; }; $mail->Timeout = $timeout; $mail->isSMTP(); $mail->Host = $hostname; $mail->SMTPAuth = true; $mail->Username = $username; $mail->Password = $password; // encryption setting if ($useEncryption === 'ssl'){ $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; } elseif ($useEncryption === 'starttls'){ $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; } $mail->Port = $usePort; // recipients $mail->setFrom($replyTo); $mail->addAddress($recipient); $mail->addReplyTo($replyTo); // content $mail->Subject = $subject; //$mail->msgHTML($body); //$mail->isHtml(true); $mail->isHtml(false); $mail->Body = $body; // send message if (!$mail->send()) { $result = [ 'result' => false, 'message' => $mail->ErrorInfo, 'debug' => $GLOBALS['debugOutput'] ]; } else { $result = [ 'result' => true, 'debug' => $GLOBALS['debugOutput'] ]; } } catch (Exception $e) { $result = [ 'result' => false, 'errorMessage' => $e->getMessage(), 'debug' => $GLOBALS['debugOutput'] ]; } finally { return $result; } } ?>