For*_*maL 5 php forms email codeigniter
做了一个简单的提交用户表格电子邮件和城市数据保存在数据库中,现在我需要在提交数据系统后添加这个表格在用户地址上生成自动电子邮件但是提到的变量我使用一个变量调用$lang如果用户输入是ar所以发送阿拉伯语的电子邮件或如果用户输入en所以用英语发送电子邮件,我面临两个问题,不知道如何在代码中修复此电子邮件类,以便我共享代码.
电子邮件类
public function email() {
$email = $this->input->post('email');
$city = $this->input->post('city');
$this->load->library('email');
$this->email->from('noreply@abc.com', 'Halalat');
$this->email->to('$emai');
$this->email->subject('Halalat Newsletter Subscription');
$this->email->message( 'Thankyou for submission' );
$this->email->send();
echo $this->email->print_debugger();
}
Run Code Online (Sandbox Code Playgroud)
控制器中的user.php
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class User extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('form');
$this->load->helper('url');
$this->load->library('user_agent');
$this->load->library('form_validation');
}
public function create_user() {
// field name, error message, validation rules
$lang = $this->input->post("lang");
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[users.email]');
$this->form_validation->set_rules('city', 'City', 'trim|required');
if ($this->form_validation->run() == FALSE) {
if ($lang == "en") {
if ($this->agent->is_mobile()) {
$this->load->view('m_english_signup');
}
else
{
$this->load->view('d_english_signup');
}
} //if ($this->agent->is_mobile())
else
{
if ($this->agent->is_mobile()) {
$this->load->view('m_arabic_signup');
}
else
{
$this->load->view('d_arabic_signup');
}
}
}
else
{
$this->load->model('Users_model');
if ($query = $this->Users_model->create_member()) {
if ($lang == "en") {
if ($this->agent->is_mobile()) {
$this->load->view('m_english_thanks');
}
else
{
$this->load->view('d_english_thanks');
}
}
else
{
if ($this->agent->is_mobile()) {
$this->load->view('m_arabic_thanks');
}
else
{
$this->load->view('d_arabic_thanks');
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
model_model.php在模型中
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Users_model extends CI_Model
{
function create_member()
{
$new_member_insert_data = array(
'email' => $this->input->post('email'),
'city' => $this->input->post('city'),
);
$insert = $this->db->insert('users', $new_member_insert_data);
return $insert;
}//create_member
}
Run Code Online (Sandbox Code Playgroud)
将电子邮件发送部分作为控制器中的一个函数:
public function sendUserMail($email)
{
$this->load->library('email');
$this->email->from('noreply@abc.com', 'Halalat');
$this->email->to('$email');
$this->email->subject('Halalat Newsletter Subscription');
$this->email->message('Testing');
$this->email->attach('/assests/images/photo1.jpg');
$this->email->send();
echo $this->email->print_debugger();
}
Run Code Online (Sandbox Code Playgroud)
在您的操作部分中,添加电子邮件功能调用
if ($query = $this->Users_model->create_member()) {
Run Code Online (Sandbox Code Playgroud)
喜欢:
$this->sendUserMail($this->input->post("email"));
Run Code Online (Sandbox Code Playgroud)