2
I am trying to send an email through the Phpmailer library, but I was not successful :/.
Server: Hostgator
Follows code:
<?php
$nome = $_POST["nome"];
$email = $_POST["email"];
$assunto = $_POST["assunto"];
$msg = $_POST["msg"];
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load composer's autoloader
require '../phpmailer/vendor/autoload.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.hostgator.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'minhaSenha'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25; // TCP port to connect to
//Define o remetente
$mail->setFrom($email, $nome);
//Define o destinatário
$mail->addAddress('[email protected]'); // Add a recipient
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $assunto;
$mail->Body = '<html>De: '.$nome.'<br/>Email:'.$email.'<br/>Assunto:'.$assunto.'Mensagem: '.$msg.'</html>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
Error message:
2018-01-12 19:18:00 SERVER -> CLIENT: 220-br802.hostgator.com.br ESMTP Exim 4.89 #1 Fri, 12 Jan 2018 17:18:00 -0200 220-We do not Authorize the use of this system to transport unsolicited, 220 and/or Bulk e-mail.
2018-01-12 19:18:00 CLIENT -> SERVER: ehlo zulpix.com
2018-01-12 19:18:00 SERVER -> CLIENT: 250-br802.hostgator.com.br Hello zulpix.com [50.116.87.189]250-SIZE 52428800250-8BITMIME250-PIPELING250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
2018-01-12 19:18:00 CLIENT -> SERVER: STARTTLS
2018-01-12 19:18:00 SERVER -> CLIENT: 220 TLS go Ahead SMTP Error: Could not connect to SMTP host.
2018-01-12 19:18:00 CLIENT -> SERVER: QUIT
2018-01-12 19:18:00 SERVER -> CLIENT: 221 br802.hostgator.com.br closing Connection SMTP Error: Could not connect to SMTP host. Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.
I was able to make it work in gmail, using the necessary settings for it and also had to enable the option in gmail "Allow less secure applications".
But I can’t send it to the hostgator’s e-mail.
Could someone help me?
OBS: We do not Authorize the use of this system to transport unsolicited, 220 and/or Bulk e-mail.
That would be a lock on their server?
I tried without tls, with tls with port 587, with port 465 + ssl and always gives the same result
– Nicolas Guilherme Matheus
@Nicolasguilhermematheus is sure it’s the same mistake, wouldn’t it be a different mistake? The log you put is on the port=25, paste the log according to the port and the correct protocol.
– Guilherme Nascimento
was going to edit the message, with ssl, the error is this one: 2018-01-12 20:52:19 SMTP ERROR: Failed to connect to server: (0) SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
– Nicolas Guilherme Matheus
@Nicolasguilhermematheus first changes the
$mail->SMTPDebug = 2;
for$mail->SMTPDebug = 3;
, forehead and take the log and then edit the question and paste the log there in the question.– Guilherme Nascimento
@Nicolasguilhermematheus what is your email domain? I believe smtp.hostgator.com is incorrect.
– Guilherme Nascimento
Guilherme Nascimento P cara, you are gods, serio, ta working now, I am since morning trying to make it work (something so simple), and as incredible as it seems, nothing worked, just I enter the stack that everything changes, thank you Guilherme heart kkk.
– Nicolas Guilherme Matheus
@Nicolasguilhermematheus for nothing, may have been a cache or other fault, how good that this solved, until more.
– Guilherme Nascimento