做了一个简单的提交用户表格电子邮件和城市数据保存在数据库中,现在我需要在提交数据系统后添加这个表格在用户地址上生成自动电子邮件但是如果提到变量我使用一个名为 $lang
的变量,如果用户输入是 ar 所以发送阿拉伯语的电子邮件或如果用户输入 en 所以用英语发送电子邮件,我面临两个问题,不知道如何在代码中修复此电子邮件类,以便我共享代码的建议 .
Email class
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();
}
user.php in controller
<?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');
}
}
}
}
}
}
users_model.php in model
<?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
}
1 回答
将电子邮件发送部分作为控制器中的功能:
在您的操作部分中,添加电子邮件功能调用
喜欢: