-1
I am having problems in a project that uses Phpmailer, the same worked normally, but now is giving problem of Connection Timeout on the site, however when I run the script via terminal the same works perfectly.
Items I’ve already checked:
- Access credentials;
- Openssl from the server;
- Version of php.ini loaded by browser x terminal;
- I debugged the code and the apparent problem is in phpmailer’s Send class all the rest of the script works perfectly.
Someone with the same problem?
<?php
try{
require 'vendors/phpmailer/src/PHPMailer.php';
require 'vendors/phpmailer/src/SMTP.php';
require 'vendors/phpmailer/src/Exception.php';
$layout = "teste servidor antigo";
$mail = new PHPMailer\PHPMailer\PHPMailer();// create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 2; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPAutoTLS = false;
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "mail.swoosh.com.br";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->CharSet = "UTF-8";
$mail->Username = "[email protected]";
$mail->Password = "password";
$mail->SetFrom("[email protected]");
$mail->Subject = "Assunto";
$mail->Body = $layout ;
$mail->AddAddress("[email protected]");
$mail->AddAddress("[email protected]");
$mail->AddAddress("[email protected]");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
}catch(Exception $e){
print_r($e);
}
Francisco the problem is that when I run this same script on the terminal, it runs quickly to fire the email
– Victor Wurthmann
There may be two problems, one is DNS as described [here] (https://techleader.pro/a/372-Fixing-slow-performance-of-sending-mail-from-PHP-via-Sendmail), but on this site [here] (https://github.com/PHPMailer/PHPMailer/wiki/Sending-to-lists#maximising-performance) recommends sending to localhost and checking the DNS cache. Maybe the command line performance is higher, due to not using php.ini (from what I understand vc tested with the same apache php.ini). Another thing we can observe is the performance in windows environments be much lower than the linux environment.
– Francisco Eduardo
Thanks guys, in fact I ended up using a solution via terminal, I stored the data in a table of the database and following a script that captures this data and assembles the email. The environment is actually Linux is a very intriguing thing
– Victor Wurthmann