【问题标题】:CodeIgniter not sending email in localhostCodeIgniter 不在本地主机中发送电子邮件
【发布时间】:2013-12-10 18:16:43
【问题描述】:

我正在尝试通过我网站的联系表发送电子邮件。 我正在使用 CodeIgniter 和 Bootstrap,以及 jquery 验证,代码如下:

HTML,来自名为“bootstrap.php”的视图代码:

               <div class="col-sm-12 contact-form" >

                   <form class="form-inline" id="validate_form" role="form" method="POST" action="index.php/site/send_email">
                      <div class="form-group">
                        <input type="text" class="form-control" id="form_name" name="form_name" placeholder="Name">
                      </div>
                      <div class="form-group">
                        <input type="email" class="form-control" id="form_email" name="form_email" placeholder="Email">
                      </div>
                     <div class="form-group">
                       <textarea class="form-control animated-textarea" id="form_message" name="form_message" placeholder="Message" cols="30" ></textarea>
                      </div>
                      <button type="submit" id="form_submit" class="btn btn-default">Submit</button>
                   </form>

               </div>  

            </div>

        </div>

Javascript:

$('#validate_form').validate({
errorElement: 'span',
rules:{
    form_name:{
        required:true,
        minlength:2

    },
    form_email:{
        required:true,
        email:true
    },

    form_message:{
        required:true,
        minlength:20,
        maxlength:500
    }
},

messages:{
    form_name:{
        required:"!",
        minlength:"!",

    },
    form_email:{
        required:"!",
        email:"!",
    },

    form_message:{
        required:"!",
        minlength: "!",
        maxlength: "!",
    }

},



});

控制器:

<?php

class Site extends CI_Controller{

    public function index()
    {
        $this->show();
    }

    public function show()
    {
        $this->lang->load('main');
        $this->load->view('bootstrap');
    }

    public function send_email()
    {

          $config = Array(
  'protocol' => 'smtp',
  'smtp_host' => 'ssl://smtp.googlemail.com',
  'smtp_port' => 465,
  'smtp_user' => '', // have my email here
  'smtp_pass' => '', // and my password here
  'mailtype' => 'html',
  'charset' => 'iso-8859-1',
  'wordwrap' => TRUE
);

        $this->load->library('email', $config);
        $name = $this->input->post('form_name', TRUE);
        $email = $this->input->post('form_email', TRUE);
        $message = $this->input->post('form_message', TRUE);
        $this->email->from($email, 'Teste');
        $this->email->to('');//my mail here
        $this->email->subject('Inside Visions Contact Message');
        $this->email->message($message);
        $this->email->send();

        if ($this->email->send()){

            $this->load->view('bootstrap');
        }
        else {
            echo 'error';
        }
    }
}

?>

缺少什么?它向我显示错误,当它没有错误时刷新页面,但我的邮箱中没有电子邮件。

【问题讨论】:

  • 您的 'localhost' 上是否安装了 '邮件服务器''正在运行'?跨度>
  • 对于我阅读的内容,对于在本地主机中发送电子邮件,我只需要我拥有的 $config 数组
  • 你需要一个邮件服务器来发送邮件。我相信你的配置假设你有一个在你的服务器上运行。
  • 我没有更改 Wamp 中的任何内容,但我认为我唯一需要的是配置数组。错误可能来自该数组或其他任何地方,我真的不知道
  • 哦,看来您正在使用外部邮件服务器,是的,您不需要本地邮件服务器。抛出的错误是什么? [引用] 缺少什么?它向我显示错误,当它没有错误时刷新页面,但我的邮箱中没有电子邮件。 [/quote]

标签: php forms codeigniter email


【解决方案1】:

试试这个!

function emailformat($c_id,$days){
            $config['protocol'] = 'smtp'; // mail, sendmail, or smtp    The mail sending protocol.
            $config['smtp_host'] = '10.10.10.10'; // SMTP Server Address.
            $config['smtp_user'] = 'email@yahoo.com.ph'; // SMTP Username.
            $config['smtp_pass'] = '12345'; // SMTP Password.
            $config['smtp_port'] = '25'; // SMTP Port.
            $config['smtp_timeout'] = '5'; // SMTP Timeout (in seconds).
            $config['wordwrap'] = TRUE; // TRUE or FALSE (boolean)    Enable word-wrap.
            $config['wrapchars'] = 76; // Character count to wrap at.
            $config['mailtype'] = 'html'; // text or html Type of mail. If you send HTML email you must send it as a complete web page. Make sure you don't have any relative links or relative image paths otherwise they will not work.
            $config['charset'] = 'utf-8'; // Character set (utf-8, iso-8859-1, etc.).
            $config['validate'] = FALSE; // TRUE or FALSE (boolean)    Whether to validate the email address.
            $config['priority'] = 3; // 1, 2, 3, 4, 5    Email Priority. 1 = highest. 5 = lowest. 3 = normal.
            $config['crlf'] = "\r\n"; // "\r\n" or "\n" or "\r" Newline character. (Use "\r\n" to comply with RFC 822).
            $config['newline'] = "\r\n"; // "\r\n" or "\n" or "\r"    Newline character. (Use "\r\n" to comply with RFC 822).
            $config['bcc_batch_mode'] = FALSE; // TRUE or FALSE (boolean)    Enable BCC Batch Mode.
            $config['bcc_batch_size'] = 200; // Number of emails in each BCC batch.

                $this->load->library('email');
                $this->email->initialize($config);
                $this->email->from('email@yahoo.com.ph', 'Robot');
                $this->email->to('email@yahoo.com.ph');
                $this->email->subject('Expiration Notification of ');
                $this->email->message('<html><body>This Message is to notify you that contract will expire in ' !</body></html>');
                $this->email->send();
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-25
    • 2013-10-01
    • 2010-12-19
    • 1970-01-01
    • 1970-01-01
    • 2016-07-22
    相关资源
    最近更新 更多