I try to send an email to a user, but once $mail->send()
is being executed, nothing happens and the web page just got stuck and hangs on for 5 minutes.
This is the $mail
setup:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once __DIR__ . '/../PHPMailer/src/Exception.php';
require_once __DIR__ . '/../PHPMailer/src/PHPMailer.php';
require_once __DIR__ . '/../PHPMailer/src/SMTP.php';
class Email {
private $mail;
function __construct() {
$config = parse_ini_file(__DIR__ . '/../../private/config.ini');
$this->mail = new PHPMailer(true);
$this->mail->IsSMTP();
$this->mail->SMTPDebug = 4;
$this->mail->SMTPAuth = true;
$this->mail->CharSet = 'utf-8';
$this->mail->Secure = 'ssl';
$this->mail->Host = $config['smtphost'];
$this->mail->Port = 465;
$this->mail->Username = $config['smtpusername'];
$this->mail->Password = $config['smtppassword'];
}
}
After 5 minutes, this message shows up in the browser:
2020-04-01 22:53:58 Connection: opening to ##mysmtphost##:465, timeout=300, options=array()
2020-04-01 22:53:58 Connection: opened
I've examined any similar problem and its solutions, but none of those seems to be helpful for my problem.
The sending:
$mail = new Email();
$mail->AddAddress($_POST['forgot_password']['email'], $foundEmail['username']);
$fromEmailAddress = ###MyHostEmailAddress###;
$fromName = ###name...###;
$mail->SetFrom($fromEmailAddress, $fromName);
$subject = ###subject..###;
$msgBody = $url;
$mail->Subject($subject);
$mail->Body($msgBody);
if($mail->Send())
$validationMessage = 'TEST'
Try to return something after the send function because i think (so I'm not sure 100% but i had such problem) the phpmailer when calling the send function use threads so it send the mail using a thread so if ur code ends or die without return the thread will be also stoped or died. Also u can dump the result of the send() if it's true that's mean that ur configuration is ok else that mean that u have a problem with it
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.