Send E-mail - Wamp and CodeIginiter

2

I'm trying to send the email via localhost through codeiginiter. Inside my libraries folder, I created a folder "PHPMailer" to put the PHPMailer files. You are not sending the email, you are giving the following error:

2015-09-24 16:53:47 CLIENT -> SERVER: EHLO localhost 2015-09-24 16:53:47    CLIENT -> SERVER: AUTH LOGIN 2015-09-24 16:53:47    CLIENT -> SERVER: bWF0aGV1c3Zvc2FAZ21haWwuY29t 2015-09-24 16:53:48  CLIENT -> SERVER: R0BNQC5FbGVj 2015-09-24 16:53:49  SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 f19sm4787092qhc.18 - gsmtp 2015-09-24 16:53:49   SMTP Error: Could not authenticate. 2015-09-24 16:53:49 CLIENT -> SERVER: QUIT 2015-09-24 16:53:50  SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

When I change the port to 587, it gives the following error:

2015-09-24 17:30:49 SMTP ERROR: Failed to connect to server: (0) 2015-09-24 17:30:49    SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

I downloaded the PHPMailer files in the Github project . I looked for other tutorials and saw that some were saying that I had to uncomment a line in php.ini . This has already been uncommented: extension=php_openssl.dll .

I've checked some tutorials too ( this and this , for example) to see what it really was doing wrong. But nothing works. I do not know if I can add it either, but I'm using Wamp on port 8080 because I'm running IIS running on port 80.

My code is here, for those who need more information:

//Minha lib
class My_email {
  function __construct(){
    require_once('PHPMailer/class.phpmailer.php');
    require_once('PHPMailer/class.smtp.php');
    require_once('PHPMailer/PHPMailerAutoLoad.php');
    require_once('PHPMailer/class.phpmaileroauthgoogle.php');
    require_once('PHPMailer/class.phpmaileroauth.php');
  }
}

//Meu controller
class email extends CI_Controller{
  function __construct(){
    parent::__construct();
    $this->load->library('My_email');
  }

  function enviaEmail(){
   $mail = new PHPMailer();
   $mail->IsSMTP(); 
   $mail->SMTPDebug = 1; 
   $mail->SMTPAuth = true; 
   $mail->SMTPSecure = 'ssl';
   $mail->Host = "smtp.gmail.com";
   $mail->Port = 465; 
   $mail->IsHTML(true);


   $mail->Username = "[email protected]"; 
   $mail->Password = "minhasenha"; 
   $mail->SetFrom('[email protected]', 'Remetente'); 
   $mail->AddReplyTo("[email protected]","Nome Completo"); 
   $mail->Subject = "Assunto"; 
   $mail->Body = "Corpo do e-mail em HTML.<br />";
   $mail->AltBody = "Corpo em texto puro.";
   $destino = "[email protected]";
   $mail->AddAddress($destino, "Pessoa Lopes Leite");

   if(!$mail->Send()) {
      echo $mail->ErrorInfo;
   } else {
      echo "Mensagem enviada com sucesso!";
   }


  }
}

Thanks for the attention and help:)

    
asked by anonymous 24.09.2015 / 19:16

1 answer

2

I was able to resolve after 3 changes:

  • Delete the lib from PhpMailer, and then download another one.
  • I just left require '/phpmailer/PHPMailerAutoload.php';
  • After the line $mail->SMTPSecure = 'tls'; I include: $mail->SMTPOptions = array('ssl' => array('verify_peer' => false,'verify_peer_name' => false,'allow_self_signed' => true));
  • Now it's working perfectly.

        
    24.09.2015 / 21:55