3
I’ve been working with Phpmailer for a while, now I’m inserting it into a more complex Content Manager and through the panel one can insert several emails to be the Phpmailer Sender in several situations (for example: contact email, password recovery, registration confirmation...), so in the manager the person can modify the email access data (host, email, password and port) and save, but when saving wanted to do a validation and only accept emails with the data that are working!
I needed a method to do a configuration test!
Does anyone know this method within Phpmailer, let it just do a connection test, but do not send any email in the act of testing.
The code I’m trying to use is this:
// Inclui o arquivo class.phpmailer.php localizado na pasta phpmailer
require_once("phpmailer/class.phpmailer.php");
require_once("phpmailer/class.smtp.php");
$host = "mx1.weblink.com.br";
$porta = 587;
$email = "[email protected]";
$senha = "teste123";
$smtp = new SMTP;
if ( !$smtp->connect($host, $porta) ) {
// erro ao conectar
echo 'Erro ao conectar o SMTP';
}
if ( !$smtp->startTLS() ) {
// erro ao iniciar TLS
echo 'Erro ao iniciar o TLS';
}
if ( !$smtp->authenticate($email, $senha) ) {
// erro ao autenticar o usuário
echo 'Erro ao autenticar o usuário de e-mail e senha';
}
The host, and the access data are real, I created to do these same tests!
I’ll test that then, thank you!
– Gabriel Garcia
Marcos, it validates tls and connect, but every time it arrives at authenticate() always error. If I use the same data in normal sending it sends the email.
– Gabriel Garcia
@Gabrielgarcia can update your question with the code you’re using to test the connection?
– Marcos Lopes
I edited the question!
– Gabriel Garcia
@Gabrielgarcia tested the location and if you don’t send the EHLO command you can’t authenticate. I updated my response with the code to send the EHLO command after starting TLS. PS: Don’t forget to remove this test user
– Marcos Lopes
Solved my problems Marcos, show! Thank you very much!
– Gabriel Garcia
@Gabrielgarcia :)
– Marcos Lopes