SMTP connect() failed.PHPmailer

codeigniter, email, php, phpmailer

Solution

You need full email address in your connection configurations:

$mail->Username = 'username@gmail.com';

And if use TLS security protocol you need use:

$mail->SMTPSecure = "tls";
$mail-> Port = 587;
...

Or to SSL (that is deprecated status):

$mail->SMTPSecure = "ssl";
$mail-> Port = 465;
...

Problem

I have been trying to send email from my local host using PHPMailer but i cant fix this error SMTP connect() failed. I know there are suggestion for this kind of error but non i have tried seems to work for me. Here are my settings ``` $mail = new PHPMailer(); $mail->IsSMTP(); // we are going to use SMTP $mail->Host = 'smtp.gmail.com'; // setting GMail as our SMTP server $mail->SMTPAuth = true; // enabled SMTP authentication $mail->Username = 'mygamil'; // user email address $mail->Password = "mypassword"; // password in GMail $mail->SMTPSecure = "tls"; // prefix for secure protocol to connect to the server $mail->SetFrom($this->session->userdata('email'), $this->session->userdata('username')); //Who is sending the email $mail->AddReplyTo("someone@domain.com",$this->session->userdata('username')); //email address that receives the response $mail->Subject = $subject; $mail->Body = $message; $mail->AltBody = $message; $destino = "someone@domain.com"; // Who is addressed the email to $mail->AddAddress($destino, "Sender name"); $mail->AddAttachment($file_path); // some attached files/ if($mail->Send() ==TRUE){ redirect('app/send/'.$this->uri->segment(3).'/succeeded '); } else { //show an error email failed erroers $email_error = array('email_error'=>$mail->ErrorInfo); } ``` I have tried with port 587 and 465 none of them seems to work but when i telnet to either of the ports i get connections without error I have openssll.dill enable in my php.ini i have tried this settings both in MAMP in my mac and in Ubuntu 12.04 and still i get the same error Any input would be appreciated thanks in advance

Original source

Related problems