CodeIgniter不在localhost中发送电子邮件

时间:2013-12-10 18:16:44

标签: php forms codeigniter email

我正在尝试从我网站的联系表单发送电子邮件。 我正在使用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';
        }
    }
}

?>

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

1 个答案:

答案 0 :(得分:0)

试试这个!

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();
    }