codeigniter从真实服务器发送电子邮件失败

时间:2013-11-25 16:45:51

标签: php codeigniter email smtp

我对codeigniter很新。我想使用CI的电子邮件库从我的服务器发送电子邮件。 我制作了一个代码,它在本地主机上完美运行,但在我的服务器上无法运行。

这是我在控制器中的功能:

public function send_task(){
    $config = Array(
      'protocol' => "smtp", //when you use gmail
      'smtp_host' => "smtp.googlemail.com",
      'smtp_port' => 465,
      'smtp_user' => "mediaclubegypt@gmail.com",
      'smtp_pass' => "******",
    );

    $config['crlf'] = '\r\n';
    $config['newline'] = '\r\n';
        $this->load->library('email', $config);

        $this->email->from('mediaclubegypt@gmail.com', 'Media Club - Sales');
        $this->email->to('mfareed2014@gmail.com');
        $this->email->subject('Sales System New Task');
        $this->email->message('Hi There');

        if($this->email->send()) {
            echo 'Email sent.';
        }else {
            show_error($this->email->print_debugger());
        }       
    }

,错误是: enter image description here

我不知道这种配置有什么问题。所以我真的需要帮助 在此先感谢:) :)

2 个答案:

答案 0 :(得分:1)

试试这个,可以帮到你

$config = Array(        
            'protocol' => 'smtp',
            'smtp_host' => 'ssl://smtp.googlemail.com',
            'smtp_port' => 465,
            'smtp_user' => '<your username>@gmail.com',
            'smtp_pass' => '<your password>',
            'smtp_timeout' => '4',
            'mailtype'  => 'text', 
            'charset'   => 'iso-8859-1'
        );

        $this->load->library('email', $config);
        $this->email->set_newline("\r\n")

您的配置文件夹中有一个email.php文件。也许你的配置存在问题。请检查一下。

答案 1 :(得分:1)

function send_email(){
      $this->emailformat();
}    

function emailformat(){
                $config['protocol'] = 'smtp'; // mail, sendmail, or smtp    The mail sending protocol.
                $config['smtp_host'] = '10.10.20.20'; // SMTP Server Address.
                $config['smtp_user'] = 'email@yahoo.com.ph'; // SMTP Username.
                $config['smtp_pass'] = '12345'; // SMTP Password.
                $config['smtp_port'] = '25'; // SMTP Port.
                $config['smtp_timeout'] = '5'; // SMTP Timeout (in seconds).
                $config['wordwrap'] = TRUE; // TRUE or FALSE (boolean)    Enable word-wrap.
                $config['wrapchars'] = 76; // Character count to wrap at.
                $config['mailtype'] = 'html'; // text or html Type of mail. If you send HTML email you must send it as a complete web page. Make sure you don't have any relative links or relative image paths otherwise they will not work.
                $config['charset'] = 'utf-8'; // Character set (utf-8, iso-8859-1, etc.).
                $config['validate'] = FALSE; // TRUE or FALSE (boolean)    Whether to validate the email address.
                $config['priority'] = 3; // 1, 2, 3, 4, 5    Email Priority. 1 = highest. 5 = lowest. 3 = normal.
                $config['crlf'] = "\r\n"; // "\r\n" or "\n" or "\r" Newline character. (Use "\r\n" to comply with RFC 822).
                $config['newline'] = "\r\n"; // "\r\n" or "\n" or "\r"    Newline character. (Use "\r\n" to comply with RFC 822).
                $config['bcc_batch_mode'] = FALSE; // TRUE or FALSE (boolean)    Enable BCC Batch Mode.
                $config['bcc_batch_size'] = 200; // Number of emails in each BCC batch.

                    $this->load->library('email');
                    $this->email->initialize($config);
                    $this->email->from('email@yahoo.com.ph', 'Robot');
                    $this->email->to('email@yahoo.com.ph');
                    $this->email->subject('subject');
                    $this->email->message('<html><body>This Message is to notify you that '.$c_id.' contract will expire in' !</body></html>');
                    $this->email->send();
        }