codeigniter - 电子邮件类 - 提交后注册 [英] codeigniter - email class - registration after submission

查看:119
本文介绍了codeigniter - 电子邮件类 - 提交后注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

做了一个简单的提交用户表单电子邮件&城市数据保存在数据库中,现在我需要在提交数据系统后添加这种形式在用户地址上生成自动电子邮件,但是提到的变量我使用一个变量 $ lang if用户输入是 ar ,因此发送阿拉伯语的电子邮件,或者如果用户输入 en 以英语发送电子邮件,有两个问题,我面对不知道如何修复此电子邮件类

 

code> 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在控制器

 <?php 

if(!defined('BASEPATH'))
exit允许直接脚本访问);

类用户扩展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(){
//字段名称,错误消息,验证规则
$ 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-> > 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在模型中

  ;?php if(!defined('BASEPATH'))exit('不允许直接脚本访问); 
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
}


解决方案

将电子邮件发送部分作为控制器中的函数:

  public function sendUserMail电子邮件)
{
$ 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();
}

在您的操作部分,在

$ b后添加电子邮件函数调用
$ b

  if($ query = $ this-> Users_model-> create_member()){
pre>

like:

  $ this-> sendUserMail this-> input-> post(email)); 


made a simple submission user form email & city data saved in database, now I need to add in this form after submission of data system generate auto email on user address but with mentioned variable i use one variable called $lang if user input is ar so send the email in arabic or if user input en so send email in english, there is two problems I face dont know how to fix this email class in code for suggestions i share code.

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
}

解决方案

Make email sending section as a function in your controller:

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

In your action section, add email function call after

if ($query = $this->Users_model->create_member()) {

like:

   $this->sendUserMail($this->input->post("email"));

这篇关于codeigniter - 电子邮件类 - 提交后注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆