【问题标题】:Send email by Email Class in codeigniter with Gmail使用 Gmail 在 codeigniter 中通过电子邮件类发送电子邮件
【发布时间】:2012-03-22 19:00:48
【问题描述】:

我想使用 gmail 在 codeigniter 中通过电子邮件类发送电子邮件,但我收到以下错误:

错误:

遇到 PHP 错误
严重性:警告
消息: mail() [function.mail]:无法连接到邮件服务器 “ssl://smtp.googlemail.com”端口 25,验证您的“SMTP”和 php.ini 中的“smtp_port”设置或使用 ini_set()
文件名: library/Email.php
行号:1553

这是我在控制中的全部功能:

function send_mail(){
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'xyz@gmail.com';
$config['smtp_pass'] = 'xxxxxxx';

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

$this->email->from('neginph@gmail.com', 'Negin Phosphate Shomal');
$this->email->to('neginfos@yahoo.com');
$this->email->subject('This is an email test');
$this->email->message('It is working. Great!');

if($this->email->send())
{
    echo 'Your email was sent, successfully.';
}

else
{
    show_error($this->email->print_debugger());
}
}

我将php.ini 中的 SMTP 更改为:

SMTP = ssl://smtp.googlemail.com
smtp_port = 25

我该怎么办?

尊重

【问题讨论】:

  • 我猜 SMTP 端口应该是 465

标签: php email gmail codeigniter-2


【解决方案1】:

这在本地主机上为我工作:

<?php
     class Email extends CI_controller
     {
        function index()
        {

         $this->load->library('email');
         $this->load->helper('url');
         $this->load->helper('form');

        $config= Array(
            'protocol'  =>'localhost',
            'smtp_host' => 'localhost',
            'smtp_port' => 'localhost',
            'smtp_user'=>  'root',
            'smtp_pass' =>''
            );

        $this->load->library('email','$config');
        $this->email->set_newline("\r\n");
        $this->email->from('nisha@gmail.com','nisha');
        $this->email->to('cse1473@gmail.com');
        $this->email->subject('this is email with subject');
        $this->email->message('it s working properly');

        if($this->email->send())
        {
            echo "your email send";
        }
        else
        {
            show_error($this->email->print_debugger());
        }
    }
}

?>

【讨论】:

    【解决方案2】:

    你打开php_openssl了吗?

    尝试在您的 php.ini 文件中取消注释 extension=php_openssl.dll

    【讨论】:

      【解决方案3】:

      这对我有用

      $email_config = Array(
                  'protocol'  => 'smtp',
                  'smtp_host' => 'ssl://smtp.googlemail.com',
                  'smtp_port' => '465',
                  'smtp_user' => 'someuser@gmail.com',
                  'smtp_pass' => 'password',
                  'mailtype'  => 'html',
                  'starttls'  => true,
                  'newline'   => "\r\n"
              );
      
              $this->load->library('email', $email_config);
      
              $this->email->from('someuser@gmail.com', 'invoice');
              $this->email->to('test@test.com');
              $this->email->subject('Invoice');
              $this->email->message('Test');
      
              $this->email->send();
      

      【讨论】:

      • 'starttls' 配置参数是否存在?它没有在文档中列出。其实我在 Codeigniter 2.0 的 CI_Email 类中没有看到过
      • 既然你提到了,我搜索了但没有找到框架中的用法
      猜你喜欢
      • 2012-05-22
      • 2017-12-07
      • 2012-12-07
      • 2012-01-07
      • 2023-03-19
      • 2014-01-24
      • 2011-10-16
      相关资源
      最近更新 更多