如何通过codeigniter中的gmail smtp发送电子邮件?

时间:2014-12-29 18:10:57

标签: php codeigniter email smtp

我的网站是Godaddy托管,其PHP版本为5.4.34。我使用了codeigniters电子邮件库,我在config文件夹下的email.php中配置了以下设置。

<?php
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'gmail account email';
$config['smtp_pass'] = 'pass';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
?>

这是我在控制器文件中的代码。

      <?php
    $msg ='';
     $msg .='<h3>Thank you for register</h3>';
      $msg .='Please follow The bellow link.';       
     $this->email->from('smit@xyz.com', 'Kayah Photography');
     $this->email->to($_POST['email']);
     $this->email->subject('Kayah Photography: Registration');
     $this->email->message($msg);
     if($this->email->send()) {
        $html ='';
        $html .= '<div class="alert alert-success" role="alert">';          
        $html .='Please check your email for details'; 
           $data['error'] = '';
           $data['success'] = $html;
           //$this->load->view('admin/new_en', $data); 
           redirect('admin/signup');
       } else { // email else
             show_error($this->email->print_debugger());
       } // email else end  
   ?> 

完成上述所有设置后,我无法解决以下错误,请有人知道如何解决此问题。

A PHP Error was encountered

Severity: Warning

Message: fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (Connection refused)

 Filename: libraries/Email.php

 Line Number: 1689

1 个答案:

答案 0 :(得分:2)

GoDaddy会阻止其托管上的所有外发SMTP连接。您必须使用其SMTP中继服务器,或使用其他主机。

http://help.godaddy.com/article/955

http://www.satollo.net/godaddy-using-smtp-external-server-on-shared-hosting