Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用codeigniter发送邮件_Php_Email_Codeigniter - Fatal编程技术网

Php 使用codeigniter发送邮件

Php 使用codeigniter发送邮件,php,email,codeigniter,Php,Email,Codeigniter,我想用codeigniter发送邮件。我使用codeigniter作为邮件发送器。我写了一个控制器并上传到网上。当我呼叫控制器时。这显示错误。我正在像这样编写控制器 <?php class Testmail extends CI_Controller { public $data = array(); public function __construct() { parent::__construct(); $this->

我想用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('kunal.saxena.kunal@gmail.com', 'Your Name');
            $this->email->to('kunal.saxena.kunal@gmail.com'); 
            $this->email->subject('Email Test');
            $this->email->message('Testing the email class.');  

            $this->email->send();

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


    }
}

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

PS.Controller看起来不错

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


如果您使用Linux或OS X作为开发环境,我强烈推荐msmtp作为一种易于配置的解决方案。让它与几乎任何电子邮件帐户一起工作都很容易,让PHP与它对话也很容易。我在我的Ubuntu开发机器上使用了这个设置,并在工作中使用了CodeIgniter项目,效果非常好。在Arch Linux wiki上有一个,尽管其中大部分应该相对容易适应其他Linux发行版或OS X。

您需要在服务器上配置
sendmail
。检查您是否安装了sendmail,并且在php.ini中正确设置了
sendmail\u path
。看起来一切正常……只要确保您的服务器配置正确……我也在codeigniter中使用了此脚本,这对我来说很好。看起来您只是复制和粘贴找到的代码,而不是阅读手册。尝试删除以下行
$config['protocol']='sendmail'$config['mailpath']='/usr/sbin/sendmail'$配置['charset']=“iso-8859-1”$config['wordwrap']=TRUE$此->电子邮件->初始化($config)为什么您希望代码工作?请为您的假设提供参考。yap当我配置在我的服务器上发送邮件时,它的代码工作正常。感谢everyoneGoogle,只有在托管网站的服务器上安装了SSL时,才能使用它。如果您在使用Gmail作为第三方时遇到问题,您可以集成其他服务。例如,SendGrid、Amazon SES和PostageApp.com。在PostageApp,我们有一个CI插件,可以使这种集成更加顺畅-免责声明:我为PostageApp工作时使用的是AmazonEC2服务器。当我在ubuntu上配置smtp安装时,这个问题得到了解决。在那之后一切都很好。
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: kunal.saxena.kunal@gmail.com
Subject: =?iso-8859-1?Q?Email_Test?=
Reply-To: "kunal.saxena.kunal@gmail.com" 
X-Sender: kunal.saxena.kunal@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <4fc358a653ad4@gmail.com>
Mime-Version: 1.0


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

Testing the email class.