php 使用 codeigniter 发送邮件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10783661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:03:31  来源:igfitidea点击:

Send mail using codeigniter

phpemailcodeigniter

提问by kunal saxena

I want to send mail using codeigniter. I am using codeigniter as mailer. i have written a controller and upload it on net . when i call the controller. This shows errors.I am writing my controller like

我想使用 codeigniter 发送邮件。我正在使用 codeigniter 作为邮件程序。我写了一个控制器并将它上传到网上。当我打电话给控制器时。这显示错误。我正在编写我的控制器

<?php

class Testmail extends CI_Controller {

    public $data = array();

    public function __construct()
    {
        parent::__construct();
        $this->load->helper('url_helper');
        $this->load->helper(array('form', 'url'));
        $this->load->library('email');
        $this->load->helper('url'); 

    }

    public function mailsend()
    {
            $config['protocol'] = 'sendmail';
            $config['mailpath'] = '/usr/sbin/sendmail';
            $config['charset'] = 'iso-8859-1';
            $config['wordwrap'] = TRUE; 
            $this->email->initialize($config);

            $this->email->from('[email protected]', 'Your Name');
            $this->email->to('[email protected]'); 
            $this->email->subject('Email Test');
            $this->email->message('Testing the email class.');  

            $this->email->send();

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


    }
}

But it is not working and i got the error like

但它不起作用,我得到了这样的错误

Exit status code: 127
Unable to open a socket to Sendmail. Please check settings.
Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Mon, 28 May 2012 10:51:18 +0000
From: "Your Name" 
Return-Path: 
To: [email protected]
Subject: =?iso-8859-1?Q?Email_Test?=
Reply-To: "[email protected]" 
X-Sender: [email protected]
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Mime-Version: 1.0


Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Testing the email class.

How to remove this error..?

如何消除这个错误..?

采纳答案by greenLizard

Make sure your server has sendmail and it is correctly set up, In case you don't have it and can't install it you can use googles SMTP server to send emails, this is what I do on localhost. You can find and example of how to do it here

确保您的服务器有 sendmail 并且设置正确,如果您没有它并且无法安装它,您可以使用 googles SMTP 服务器发送电子邮件,这就是我在 localhost 上所做的。您可以在此处找到如何操作的示例

PS. Controller looks fine

附注。控制器看起来不错

回答by Matthew Daly

You need to have an MTA (mail transfer agent) installed on the computer to actually send the email, and PHP needs to be configured to use it to send email.

您需要在计算机上安装 MTA(邮件传输代理)才能实际发送电子邮件,并且需要配置 PHP 以使用它来发送电子邮件。

If you're using Linux or OS X as your development environment, I can highly recommend msmtp as an easy-to-configure solution for this. It's really easy to get it working with pretty much any email account, and it's also easy to get PHP to talk with it. I use exactly this setup on my Ubuntu development machine with a CodeIgniter project at work, and it works really well. There's a great tutorial that covers thison the Arch Linux wiki, although most of it should be relatively easy to adapt to other Linux distros or OS X.

如果你使用 Linux 或 OS X 作为你的开发环境,我强烈推荐 msmtp 作为一个易于配置的解决方案。让它与几乎任何电子邮件帐户一起工作真的很容易,而且让 PHP 与之交谈也很容易。我在运行 CodeIgniter 项目的 Ubuntu 开发机器上完全使用这个设置,它运行得非常好。Arch Linux wiki 上有一个很好的教程,涵盖了这一点,尽管其中大部分应该相对容易适应其他 Linux 发行版或 OS X。