2014-05-12 07:05
采纳率: 100%
浏览 54


I use php mailer for sending email in zf2 but email not send i used gmail authentication in php mailer but when i run code it gives me following error:

SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: System error (0) SMTP connect() failed. Mailer Error: SMTP connect() failed. 

I used this Error sending e-mail using Gmail SMTP but same error exist

how i remove this error and send email? here is my code:

public function addAction()
    //check permissions
    if(!$this->acl->isAllowed($this->user->user_type, 'user.create'))
    $this->layout()->top_heading = 'Add User';  
    $dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');
    $form = new UserForm();
        $post = $this->getRequest()->getPost();
            $s = new User();
            $user = $dm->getRepository('Calendar\Document\User')->findOneBy(array(
                "username" => $formData['username']
            $email = $dm->getRepository('Calendar\Document\User')->findOneBy(array(
                "email" => $formData['email']
            if($user || $email)
                $message='User Already Exists.';    
                $message="Select Some Other Role."; 
                $s->setProperty('dataentered',date('Y-m-d H:m:i'));
                //echo new Response($s->getProperty('id'));
                $message='User Added Successfully.';
                $form = new UserForm();

                $mail  = new \PHPMailer();   

                //GMAIL config
                $mail->SMTPAuth   = true;                  // enable SMTP authentication
                $mail->SMTPSecure = "ssl";                 // sets the prefix to the server
                $mail->Host ="smtp.gmail.com:465";      // sets GMAIL as the SMTP server

                $mail->Username   = "marif252@gmail.com";  // GMAIL username
                $mail->Password   = "password";            // mygmail password
                $mail->SMTPDebug = 1;
                //End Gmail

                $mail->From       = "marif252@gmail.com";
                $mail->FromName   = "Muhammad Arif";
                $mail->Subject    = "User Confirmation";
                $mail->MsgHTML("the message");

                //$mail->AddReplyTo("reply@email.com","reply name");//they answer here, optional
                $mail->IsHTML(true); // send as HTML

                if(!$mail->Send()) {//to see if we return a message or a value bolean
                    echo "Mailer Error: " . $mail->ErrorInfo;
                } else  echo "Message sent!";

    return array( 'form' => $form, 'add_message' => $message, 'update' => $update, 'user'=>$this->user );

how i use php mailer using gmail authentication for send email?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题