2012-06-04 3 views
0

양식에서 Gmail로 전자 메일을 보내려면 아래 코드로 고생했습니다. 그러나 나는 포기한다.배 패키지를 사용하여 양식을 gmail로 보내는 방법

      require_once('../php/Mail.php'); 
          require_once('../php/Mail/RFC822.php'); 
          //function to send email 
          function send_email($to,$from,$subject,$body,$is_body_html=false) { 
           if(! valid_email($to)) 
           { 
            throw new Exception('This email address in invalid: '.htmlspecialchars($to)); 
           } 
           if(! valid_email($from)) 
           { 
            throw new Exception('This email address in invalid: '.htmlspecialchars($from)); 
           } 
           //set up an array which can hold the SMTP server detail 
           $smtp=array(); 
           $smtp['host']='ssl://smtp.gmail.com'; 
           $smtp['port']=465; 
           $smtp['auth']=true; 
           $smtp['username']='[email protected]'; 
           $smtp['password']='my_pass'; 

           //create the mailer object using which can connect to your SMTP server 
           $mailer=Mail::factory('smtp',$smtp); 
           //check the returned value when creating the mailer object 
           if(PEAR::isError($mailer)) 
            { 
            throw new Exception('Could not create the mailer object.'); 
            } 
           //as the send method of the mailer object accepts the reciepients and headers as an array, create 
           //and set up the arrays 

           $recipients=array(); 
           $recipients['to']=$to; 

           $headers=array(); 
           $headers['from']=$from; 
           $headers['to']=$to; 
           $headers['subject']=$subject; 
           //check if the content is set to be html 
           if($is_body_html) 
            { 
            $headers['Content-type']='text/html'; 
            } 
           //send the email 
           $result=$mailer->send($recipients,$headers,$body); 
           //check the returned value when sending the email 
           if(PEAR::isError($result)) 
            { 
            throw new Exception('There was an error while trying to send the email: '.htmlspecialchars($result)); 
            } 
          } //end of send_email function 

내가 가진 오류 메시지가 나는 이유를 이해할 수 없다

Error: exception 'Exception' with message 'There was an error while trying to send the email: Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: Connection timed out (code: -1, response:)]' in /home/biwucr/public_html/functions/mailer_function.php:49 Stack trace: #0 /home/biwucr/public_html/send-quote.php(62): send_email('[email protected]', 'Yibeltal sour...', false) #1 {main}

다음과 같습니다 아래의 코드를 참조하십시오.

호스트 회사에 연락해야합니까?

+0

문제는 Gmail의 SMTP 서버로의 연결입니다 .. 설정이 정확합니까? – shadyyx

+0

GMAIL SMTP에 대한 구성을 알려주시겠습니까? – user1062893

답변

1

Gmail의 SMTP 서버 주소는 이고 SMTP.GOOGLEMAIL.COM은 SMTP.GMAIL.COM이 아닙니다.

따라서 설정이되어야합니다 :

// ... 
$smtp=array(); 
$smtp['host']='ssl://smtp.googlemail.com'; 
// ... 
+0

고맙습니다.하지만 ssl : //smtp.googlemail.com을 사용해 보았습니다. 변경 사항이 없습니다. – user1062893

+0

귀하의 ** 사용자 이름 ** 및 ** 비밀번호 **가 귀하의 SMTP에 맞습니까? – shadyyx

+0

shadyyx 주셔서 감사합니다.하지만 비밀번호와 사용자 이름은 확실합니다. 나는 뭔가를 기대하고있다. 서버에 SSL 인증서를 설치해야합니까? 내 호스트가 내가 호스트 서비스를 구입할 때 ssl 인증서를 구입하도록 요청했는데 그렇게하지 않았습니다. 이유가 될 수 있을까요? – user1062893

1

당신은 php.ini 파일에서이 줄을 주석을 시도 할 수 있습니다 :

extension=php_openssl.dll 
관련 문제