Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SMTP connect() failed.PHPmailer

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("[email protected]",$this->session->userdata('username'));  //email address that receives the response
                $mail->Subject    = $subject;
                $mail->Body       = $message;
                $mail->AltBody    = $message;
                $destino = "[email protected]"; // 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

like image 312
Emmanuel Mariki Avatar asked Feb 13 '23 22:02

Emmanuel Mariki


2 Answers

You need full email address in your connection configurations:

$mail->Username = '[email protected]';

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;
...
like image 172
Steven Koch Avatar answered Feb 20 '23 00:02

Steven Koch


Check your php.ini file, on it, if you have this:

;extension=php_openssl.dll

change it to

extension=php_openssl.dll
like image 22
Tanmay Patel Avatar answered Feb 20 '23 00:02

Tanmay Patel