如何在codeigniter网站上不使用SMTP协议发送电子邮件

时间:2016-10-21 07:27:21

标签: php codeigniter

我正在我的网站创建联系我们页面,该网站位于CodeIgniter中。我想将此联系表格数据发送到我的邮箱地址。

如何在不使用SMTP网站的情况下在CodeIgniter中发送电子邮件?

2 个答案:

答案 0 :(得分:2)

是的,您可以使用codeIgniter简单邮件功能。

  

实施例: -

  public function send_mail() { 
         $from_email = "your@example.com"; 
         $to_email = $this->input->post('email'); 

         //Load email library 
         $this->load->library('email'); 

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

         //Send mail 
         if($this->email->send()) 
         $this->session->set_flashdata("email_sent","Email sent successfully."); 
         else 
         $this->session->set_flashdata("email_sent","Error in sending Email."); 
         $this->load->view('email_form'); 
      }

答案 1 :(得分:0)

您可以发送电子邮件 控制器。

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Inquiry extends CI_Controller
{
    public function inquiry()
    {
        parent::__construct();
        /* Model */
    }

    public function index()
    {
        $this->load->view('header', array("title" => "Inquiry"));
        $this->load->view('your_view',$view);
        $this->load->view('footer');
    }

    function inviteStaff()
    {
        $this->load->library('email');
        $from_email = $_POST['email'];
        $to_email = "your@email.com";
        $body='이름 : '.$_POST['name'].'<br /><br />email : '.$_POST['email'].'<br /><br />contents : '.$_POST['contents'].'';

        $this->email->from($from_email, $_POST['name']);
        $this->email->to($to_email);
        $this->email->set_mailtype("html");
        $this->email->subject('TITLE');
        $this->email->message($body);
        $this->email->send();
    }

    function emailCheck()
    {
        $user_id = base64_decode($_POST['user_id']);
        $email = $_POST['check_mail'];
        $where = array('user_emailId' => $email,'user_id!=' => $user_id);
        $view = $this->mdl_file->sel_where('user_details',$where);
        echo count($view);
    }
}

图。

<form class="form-horizontal form-label-left" method="POST" action="<?php echo base_url();?>Inquiry/inviteStaff">
  <div class="item form-group" id="email_div">
  <label class="control-label col-md-3 col-sm-3 col-xs-3 right" for="name">이름<span class="required">*</span>
  </label>
  <div class="col-md-6 col-sm-6 col-xs-6" >
    <input type="text" id="name" name="name" required="required" class="form-control col-md-7 col-xs-12" placeholder="이름" onblur="return emailCheck();" value="<?php echo @$staff_details[0]['user_emailId'] ?>">
  </div>
  <div class="alert">Your Name.</div>
    <div class="alert_1" style="position: absolute;margin-left: 735px;width: 160px;display: none;margin-top: 5px;color: red;">
    </div>
  </div>
  <div class="item form-group" id="email_div">
  <label class="control-label col-md-3 col-sm-3 col-xs-3 right" for="email">E-mail<span class="required">*</span></label>
  <div class="col-md-6 col-sm-6 col-xs-6" >
    <input type="text" id="email" name="email" required="required" class="form-control col-md-7 col-xs-12" placeholder="Email" onblur="return emailCheck();" value="<?php echo @$staff_details[0]['user_emailId'] ?>">
  </div>
  <div class="alert">Your Email.</div>
    <div class="alert_1" style="position: absolute;margin-left: 735px;width: 160px;display: none;margin-top: 5px;color: red;">
    </div>
  </div>
  <div class="item form-group" id="email_div">
    <label class="control-label col-md-3 col-sm-3 col-xs-3 right" for="contents">내용<span class="required">*</span></label>
    <div class="col-md-6 col-sm-6 col-xs-6" >
      <textarea id="contents" name="contents" required="required" class="form-control col-md-7 col-xs-12" placeholder="내용" onblur="return emailCheck();" value="<?php echo @$staff_details[0]['user_emailId'] ?>" style="height:200px">
      </textarea>
	</div>
	<div class="alert">Contents.</div>
	  <div class="alert_1" style="position: absolute;margin-left: 735px;width: 160px;display: none;margin-top: 5px;color: red;">
      </div>
	</div>
</form>