Ir ao conteúdo
  • Cadastre-se

Enviar emails com phpmailer.


Posts recomendados

To tentando aprender a usar essa classe, porque a mail() do php só me da problema mas esta me dando erro.

 

Citação

Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

 

<?php
require("phpmailer/class.phpmailer.php");
require("phpmailer/PHPMailerAutoload.php");

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.hostinger.com.br';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '[email protected]/';                 // SMTP username
$mail->Password = '123456789';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('[email protected]', 'Mailer');
$mail->addAddress('[email protected]', 'Joe User');     // Add a recipient
$mail->addAddress('[email protected]');               // Name is optional
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');

//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

?>

 

Link para o comentário
Compartilhar em outros sites

  • Moderador

@FabianoS Tenta retirar esta linha: 

require("phpmailer/class.phpmailer.php");

Porque você já incluiu o autoload.

 

Então, ou tu deixa só o require no PHPMailerAutoload.php ou  retira ele e incluir manualmente o class.phpmailer e o class.smtp.php

 

A explicação está naquela página que você postou!

 

Citação

Including the wrong file

Not so long ago, PHPMailer changed the way that it loaded classes so that it was more compatible with composer, many frameworks, and the PHP PSR-0 autoloading standard. Note that because we support PHP back to version 5.0, we cannot support the more recent PSR-4 standard, nor can we use namespaces. Previously, PHPMailer loaded the SMTP class explicitly, and this causes problems if you want to provide your own implementation. You may have seen old scripts doing this:


require 'class.phpmailer.php';

If you do only that, SMTP sending will fail with a Class 'SMTP' not found error. You need to either explicitly include the class.smtp.php file, or use the recommended approaches of using composer or the supplied autoloader, like this:


require 'PHPMailerAutoload.php';

 

Link para o comentário
Compartilhar em outros sites

@dif Eu tentei usar só a 

require("phpmailer/PHPMailerAutoload.php");

Só que retornou mesmo erro.

 

Att: Na verdade foi um erro meu, primeira  vez que tinha visto aquilo , achei que era só acrescenter o "smtp" no hostinger.com.br mas na verdade tinha o nome certo que seria "mx1.hostinger.com.br".

 

So que agora ele demora pra carregar e depois da "500 Internal Server Error"

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...