Phpmailer does not work email

Asked

Viewed 966 times

-1

I have the code to follow:

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.

  • Would not be $mail->isSMTP() in place of $mail->isSMTP = true?

  • I use it like this: require_once '../../lib/phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;

  • include(SMTP.php): failed to open stream: No such file or directory appeared when I tried to switch to issmtp();

  • i tried switching to phpmailerautoload.php and continues with the same error

  • @Rods, you have in your project the file class.smtp.php that is part of the PHPMailer?

  • Yeah, I got it from my friend down there, but thanks!

Show 1 more comment

1 answer

1


Try it like this:

  1. Download their Github repository, using the "Clone or Download Button" https://github.com/PHPMailer/PHPMailer
  2. Place in the project folder
  3. Do the autoload require
  4. And configure with your server data, and use $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 is easier. If you need help just let us know.

  • nice, Thank you!! "I accepted the answer" ^^

Browser other questions tagged

You are not signed in. Login or sign up in order to post.