php - 无法使用 PHP mail() 发送电子邮件。您的服务器可能未配置为使用此方法发送邮件

标签 php codeigniter

我尝试使用 codeigniter 框架发送邮件。但它会引发错误“无法使用 PHP mail() 发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。

From: "prakash t" <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="087c787a6963697b60636b6d486f65696164266b6765" rel="noreferrer noopener nofollow">[email protected]</a>>
Return-Path: <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5f2b2f2d3e343e2c37343c3a1f38323e3633713c3032" rel="noreferrer noopener nofollow">[email protected]</a>>
Reply-To: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3e4a4e4c5f555f4d56555d5b7e59535f5752105d5153" rel="noreferrer noopener nofollow">[email protected]</a>" <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c4b0b4b6a5afa5b7acafa7a184a3a9a5ada8eaa7aba9" rel="noreferrer noopener nofollow">[email protected]</a>>
X-Sender: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d5a1a5a7b4beb4a6bdbeb6b095b2b8b4bcb9fbb6bab8" rel="noreferrer noopener nofollow">[email protected]</a>
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7b4e1a1e1f4f1e1e1f4f4b4e4b4d3b1c161a121755181416" rel="noreferrer noopener nofollow">[email protected]</a>>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
=?UTF-8?Q?Test=20Mail?=
hai this my test mail

” 但没有用

这是我的代码:

公共(public)函数sendMail(){

    $config = Array(
        'protocol' => 'mail',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 587,
        'smtp_user' => 'e<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="463e272b362a2306212b272f2a6825292b" rel="noreferrer noopener nofollow">[email protected]</a>',
        'smtp_pass' => '*********'
    );

我知道这是重复的问题。但我没有找到问题的解决方案

    $this->load->library('email',$config);

    $this->email->set_newline("\r\n");
    $this->email->from('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="add9dddfccc6ccdec5c6cec8edcac0ccc4c183cec2c0" rel="noreferrer noopener nofollow">[email protected]</a>','prakash t');
    $this->email->to('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7b0f0b091a101a08134a4a4a494a42424d3b1c161a121755181416" rel="noreferrer noopener nofollow">[email protected]</a>');
    $this->email->subject('Test Mail');
    $this->email->message('hai this my test mail');

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

}

最佳答案

您已完成所有操作,但在初始化邮件时遇到问题

只需更改此

$this->load->library('email',$config);

$this->load->library('email');
$this->email->initialize($config);

您可以查看in details here.

关于php - 无法使用 PHP mail() 发送电子邮件。您的服务器可能未配置为使用此方法发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50186498/

相关文章:

php - 由数据库填充的自动完成表单?

php - 查找两个日期之间的时差

php - 面向 Internet 的 SSRS 报告

javascript - 使用 select 的全日历过滤事件

php - 具有上下文的基于角色的访问控制(RBAC)?

php - 在 PHP 中获取表单中文件上传字段的完整路径

php - 如何查看Mysql表有没有变化?

php - 在 MySQL 查询中的 where 子句中传递变量 PHP CodeIgniter

codeigniter - 使用谷歌登录总是征求用户同意

mysql - 如果该行具有相同的值,则将光标移动到下一个