CI SMTP gmail发送

时间:2014-02-27 14:25:07

标签: php codeigniter email smtp

电子邮件正在本地发送,但在网站上传时会出错 这里是图书馆的代码请帮忙

<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Emaillib {

    function send_email($fromEmail, $fromName, $details) {
        $CI = & get_instance();
        $CI->load->library('email');

        $config['protocol'] = 'smtp';
        $config['smtp_host'] = 'ssl://smtp.gmail.com';
        $config['smtp_port'] = '465';
        $config['smtp_timeout'] = '7';
        $config['smtp_user'] = 'abc@gmail.com'; // Email
        $config['smtp_pass'] = '*****'; // Password
        $config['charset'] = 'utf-8';
        $config['newline'] = "\r\n";
        $config['mailtype'] = 'html'; // or html
        $config['validation'] = TRUE; // bool whether to validate email or not

        $CI->email->initialize($config);

        $CI->email->from($fromEmail, $fromName);
        $CI->email->to('abc@xyz.com'); // To Email
        $CI->email->reply_to($fromEmail, $fromName);

        $CI->email->subject('Enquiry through Website');
        $CI->email->message($details);

        $isSent = $CI->email->send();
        //echo $CI->email->print_debugger();

        if (!$isSent) {
            return 'false';
        }
        return 'success';
    }

}

&GT;

1 个答案:

答案 0 :(得分:0)

因为你说它在本地工作正常,它表明它是代码的问题,而是服务器配置。很难说确切的问题是什么,但我会做以下

  • 检查服务器日志文件是否有任何错误
  • 通过检查以下行是否已取消注释extension=php_openssl.dll
  • ,确保您已在php.ini中启用了SSL
  • 确保端口465已打开

尝试开始并看看会发生什么