Enviar E-mail - Wamp e Codeiginiter

Asked

Viewed 279 times

2

I’m trying to send the email via localhost by codeiginiter. Inside my Ibraries folder, I created a "Phpmailer" folder to put the Phpmailer file. Not sending the email, is 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 door to 587, 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 on Github of the project. I looked for other tutorials and saw that some said I had to uncomment a line on php.ini. This one’s already been discolored: extension=php_openssl.dll.

I checked some tutorials as well (this and this, for example) to see what he was really doing wrong. But nothing works. I don’t know if you can add it either, but I’m using the Wamp at gate 8080, because I’ve got the IIS running at gate 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 your attention and help :)

  • The error said that authentication failed ..., it may be the wrong password, wrong port etc.

  • @rray I made an edition there, give a look please...

  • 1

    I’m in the same trouble you are, I uninstalled Xampp, I released port 80 from IIS, I installed Xampp again. I restarted the machine and it worked, sent about 5 emails, until the moment it stopped and I’m having the same problem again! Following the topic here!

1 answer

2

I managed to solve after 3 amendments:

  1. Delete lib from Phpmailer, and downloaded again another.
  2. I just left the require '/phpmailer/PHPMailerAutoload.php';
  3. After the line $mail->SMTPSecure = 'tls'; i includes: $mail->SMTPOptions = array('ssl' => array('verify_peer' => false,'verify_peer_name' => false,'allow_self_signed' => true));

Now it’s working perfectly.

  • In my case I am using smtsecure as tls, and the port is 587. I did not test with ssl to see if it works.

  • you downloaded where? Can edit with the link, please. I will test your solution tomorrow.

  • https://github.com/PHPMailer/PHPMailer

  • Dude, I tried it here and it didn’t work. But I made a change that worked, in parts. I took a domain I had and put it to send the email. When I put it there on the screen, it gave error but sent. When I opened the destination email box, the email even arrived, only it arrived in spam. Normal?

Browser other questions tagged

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