Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

php - codeigniter - email class - registration after submission

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('[email protected]', '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
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Make email sending section as a function in your controller:

public function sendUserMail($email)
{
  $this->load->library('email');

$this->email->from('[email protected]', '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"));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...