<?php
class Email extends Controller {

    function Email()
    {
        parent::Controller();   
        $this->load->library('email');
    }

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

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

        $this->email->from('mygmail@gmail.com', 'myname');
        $this->email->to('target@gmail.com'); 

        $this->email->subject('Email Test');
        $this->email->message('Testing the email class.');  

        $this->email->send();

        echo $this->email->print_debugger();

        $this->load->view('email_view');
    }
}

我得到了这个错误:

A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Connection timed out)
Filename: libraries/Email.php
Line Number: 1641

使用PORT 25/587

我犯了这个错误:

A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:func(119):reason(252)
Filename: libraries/Email.php
Line Number: 1641

我现在不想用phpmailer.(实际上,我曾try 使用phpmailer,但失败了).

伙计们,我该怎么解决这个问题?

推荐答案

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'xxx',
    'smtp_pass' => 'xxx',
    'mailtype'  => 'html', 
    'charset'   => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");

// Set to, from, message, etc.

$result = $this->email->send();

CodeIgniter Forums

Php相关问答推荐

打印SQL表内容时在DIV内添加断点

未找到laravel cascadeOnEdit

尽管包含目标日期,但日期范围比较仍有意外输出

一列必须指定多个变量的Laravel查询

让所有具有相同名称的产品在WooCommerce中更改价格

使用PHP curl的Amazon SP API批处理调用

PHP MySQL求和子树并与父树累加

Symfony 6.2 IsGraned具有多个角色

如果为布尔值,则 for each 循环重新启动

在WP工具中页面加载时可短暂看到的JavaScript生成的字段

在PHP项目中安装OpenAI PHP SDK时出现问题

Google Drive API:为什么使用服务帐户在下载文件时会将我带到 Google Drive 登录窗口?

在 groupBy laravel 5.7 中 Select 多列

从图像URL中获取文件扩展名?

PHP文件如何从CSS执行

PHP使用三元运算符进行null合并(再次)

Laravel:ArgumentCountError: 函数 App\Mail 的参数太少

Symfony 迁移判断器在我的工作中失控

如果 static:: 被解析为B,为什么 PHP 会执行A的方法

如何从 PHP 中的字符串位置排除图像扩展名