PHPmailer does not work email

-1

I have the following code:

require_once('c:\wamp64\www\phpmailer\class.phpmailer.php');


$mail = New PHPMailer();
//$mail-> ErrorInfo;
//exit;
$mail->IsSMTP = true;
//$mail-> ErrorInfo;
//exit;
$mail->SMTPSecure = "ssl";
//$mail-> ErrorInfo;
//exit;
$mail->Host = "smtp.host.com.br";
//$mail-> ErrorInfo;
//exit;
$mail->Port = 465;
//$mail-> ErrorInfo;
//exit;
$mail->Username = "[email protected]";
$mail->Password = "senha123";
//$mail-> ErrorInfo;
//exit;

$mail->From = "[email protected]";
$mail->FromName = "Suporte";
//$mail-> ErrorInfo;
//exit;
$mail->Subject = "Teste de Envio";
$html = "aa !";
$text = "aa ! ";
$mail->Body = $html;
$mail->AltBody = $text;
//$mail-> ErrorInfo;
//exit;
$mail->AddAddress("[email protected]", "suporte");
//$mail-> ErrorInfo;
//exit;
if (!$mail->Send()){
echo "Erro DNOVO !".$mail->ErrorInfo;
} else {
echo "ALELUIA DEU CERTO !";
}

It returns the following error:
Erro DNOVO !Could not instantiate mail function.

    
asked by anonymous 09.03.2017 / 18:53

1 answer

1

Try this:

  • Download their Github repository using the "Clone or Download" button link
  • Places in the project folder
  • Requires autoload
  • E configures with your server data, and uses $mail->isSMTP()

    <?php
    require 'PastaDoPHPMailer/PHPMailerAutoload.php'; // Troca aqui pela pasta que baixou do repositório.
    
    $mail = new PHPMailer;
    
    //$mail->SMTPDebug = 3;                               // Enable verbose debug output
    
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = '[email protected]';                 // SMTP username
    $mail->Password = 'secret';                           // 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';
    }  
    
  • With composer it is easier. If you need help just let me know.

        
    09.03.2017 / 20:37