5

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
}
analyticalpicasso
  • 1,955
  • 6
  • 23
  • 45
FormaL
  • 359
  • 2
  • 4
  • 19
  • **there is two problems i face** what is the two problems? – Kumar V Jan 18 '14 at 07:38
  • 1- How to implement email class and where. 2- How to manage two language input with email class. – FormaL Jan 18 '14 at 07:56
  • For 1: refer this http://stackoverflow.com/q/16969572/270037 – Kumar V Jan 18 '14 at 16:32
  • 1
    @kumar_v Thankyou so much i will try to learn and implement this in code. – FormaL Jan 19 '14 at 06:33
  • @kumar_v as you mentioned the link i check it guide only the email class and my question is still the same, email function is already ready but i want to know when i submit form this function triger and send email to user, do you know how i triger this email function with submit button. – FormaL Jan 19 '14 at 06:36
  • After create_member(), you have to send email. For sendng email in CI, you check the user guide. – Kumar V Jan 19 '14 at 06:38
  • if i will already understand this problem then why i ask here sir! – FormaL Jan 19 '14 at 06:39
  • Where is email code exist? in same controller or some other file? – Kumar V Jan 19 '14 at 06:45
  • i already mention the email function in question – FormaL Jan 19 '14 at 07:08
  • i need when user submit the data so send email to user only this i need. – FormaL Jan 19 '14 at 07:09
  • @kumar_v i update email function here and i use this function in controller user.php and now i want to trigger this function when user submit the form. – FormaL Jan 19 '14 at 07:13
  • sorry formal i was not able to check this before.hope you got the answer :) – user2936213 Jan 20 '14 at 04:58
  • Yes teacher i got it answer and solve this, now try to learn functions & variables of php :/ – FormaL Jan 20 '14 at 06:10

1 Answers1

1

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"));
Kumar V
  • 8,669
  • 8
  • 37
  • 55
  • thankyou so much i add on local server stmp off so i test on international server but i need some changes please guide i add this `$config = Array( 'protocol' => 'smtp', 'smtp_host' => 'ssl://smtp.googlemail.com', 'smtp_port' => '465', 'smtp_user' => 'someuser@gmail.com', 'smtp_pass' => 'password', 'mailtype' => 'html', 'starttls' => true, 'newline' => "\r\n" );` – FormaL Jan 19 '14 at 07:21
  • so config setting i mention in same function ? – FormaL Jan 19 '14 at 07:21
  • 1
    yes. you can. But, email functionality will be used in some other controller also. So just create a `helper` and place this email function in that helper. auto load this helper in your config. So you can use anywhere in the project. – Kumar V Jan 19 '14 at 07:24
  • i m not an expert to make helper i am very new in codeigniter even php too i will try as you guide i will use. – FormaL Jan 19 '14 at 07:26
  • `Your message has been successfully sent using the following protocol: mail From: "Halalat" Return-Path: Reply-To: "fahadvintage@gmail.com" X-Sender: fahadvintage@gmail.com X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: <52db84d14d77a@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit =?utf-8?Q?Halalat_Newsletter_Subscription?= Testing` **not sending email to user email return to my email again with errors** – FormaL Jan 19 '14 at 07:56
  • but you are getting success message. how? – Kumar V Jan 19 '14 at 07:59
  • [link](http://fahad.myradio.pk) **you visit link just fill up form** email send and in my gmail spam folder msg come but email sending on user provided email id. – FormaL Jan 19 '14 at 08:05
  • $email not working , this variable not get data from input post properly how can i fix this. – FormaL Jan 19 '14 at 08:52
  • i fix sending mail for single user. – FormaL Jan 19 '14 at 10:10