简体   繁体   中英

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("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

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;
...

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

;extension=php_openssl.dll

change it to

extension=php_openssl.dll

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM