SMTPDebug = 3; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = $smtpHost; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = $sender; // SMTP username $mail->Password = $credential_pw; // SMTP password $mail->SMTPSecure = $algo_sec; // Enable TLS encryption, `ssl` also accepted $mail->Port = $post; // TCP port to connect to $mail->isHTML(false); // Set email format to HTML $mail->setFrom($sender, $senderName); $mail->Subject = $subject; $file = fopen($filename, "r"); while(!feof($file)){ $line = fgets($file); $sanitized_mail = filter_var($line, FILTER_SANITIZE_EMAIL); if($sanitized_mail !== false) { $mail->addAddress($sanitized_mail); $token = getToken(); $link = generateLink($mlrollmember_url, $token, $ml, $sanitized_mail); $mail->AltBody = $def_body.$link; if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; } } } fclose($file);