Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6914191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:18:56+00:00 2026-05-27T09:18:56+00:00

I am using the following code to send email in codeigniter and would like

  • 0

I am using the following code to send email in codeigniter and would like to know where the best place to put the code is.

It currently exists in my controller but is to bulky and I am sure there is a better place for it.

The way my email code works is that I set the variables that I want in the email and then input them into the template and send.

I will be having more than one email being sent on my site so where should I put the code and how. (library helper??)

Code:

                $this->load->library('email');
                $this->email->initialize();

                $this->email->from('noreply@domain.com', 'domainy');
                $email = $this->input->post('email_address');
                $this->email->to($email); 
                $this->email->subject('Great question. We will answer it as soon as we can');

                $emaildata['title'] = 'Company - Ask us a question';
                $emaildata['preheader_teaser'] = 'Your question has been received and we will be answering it shortly. Please keep an eye on your inbox for our response.';
                $emaildata['preheader_links'] = '   <em><b>Do not reply to this email</b></em>';
                $emaildata['header_image'] = 'http://www.domain.com/assets/img/logo.png';
                $emaildata['body_content'] = '
                <h1>Hi '.$this->input->post('first_name').',</h1>
                <h2 style="color:#ccc !important;">Great question!</h2>
                <p>Your question has been submitted to our consultants and received with thanks. We will answer you question as soon as we can.</p>
                <p>Response generally takes within 24 to 48 hours and will be in the form of an email or (if provided) a telephone call.</p>
                <p>We will handle your question in the most efficient way possible and get back to you with an answer as soon as we can.</p>
                <p>Have a super day!</p>
                <h4  style="color:#1a3665 !important;">Your question to us:</h4>
                '.$this->input->post('question').'          
                ';
                $emaildata['footer_social_links'] = 'Follow us on ';
                $emaildata['footer_copyright'] = 'Copyright &copy; domain MMXI, All rights reserved.';
                $emaildata['footer_description'] = '"Impartial, help and assistance, as and when you need it"';
                $emaildata['footer_mailing_address'] = 'enquiries@domain.com';
                $emaildata['footer_utility_links'] = '<a href="http://www.domain.com/">www.domain.com</a>';
                $emaildata['footer_rewards'] = '&nbsp;';

                $emailbody = $this->load->view('email/templates/simple-basic',$emaildata,true);

                $this->email->message($emailbody);  
                $this->email->send();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:18:56+00:00Added an answer on May 27, 2026 at 9:18 am

    Well, there’s not much to say: if you cannot reduce the code, wherever you put it it’s always that “bulky” 🙂

    Me, I would have stored it in a model. Since to me it looks like…a model, that you’re going to use multiple times, so it fits nicely in the concept. But a library would be fine too, I’m not saying that.

    Something that strikes me, is that all your view variables – apart from the Post one – are hardcoded…Are you telling me you’re hardcoding different values depending on the method that calls the email library, or those are all fixed? In the latter case, why not just create a “template” view with the only variable being the, actually, really variable text? (“post” ones, I mean).

    If those are variables, but to some extent, you might also considering using a custom config file holding in each key the different possibilities.


    Summing up, it really depends on the degree of customization each email has:

    1. If the only changing thing is the post values, pass only those to a template.
    2. If other fields are changing, but not much and all withing a fixed range of possibilities, use a custom config file.
    3. If you’re going to declare every time a different variable, well, wherever you put it you’ll always have to write them over again, so controller, model, or library won’t change anything.
    4. What about using a database, wich stores different templates? You can use the built-in templating library tu change just the variable bits, and then pass the processed template to the e-mail library.

    I await for further details to improve my answer

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to send an email using codeigniter, and would like the message to
I want to send an email with an attachment using the following code (Python
I am using the following code to send an email with a pdf attachment:
I am using following code to create and send email through CGI perl. The
I am using the following code to send an email attachment. I'm using C#,
I'm using the following code to send an email from my vb.net web application.
Using the Apache Commons to send email there is the following code. HtmlEmail email
I am Using Following Code for Send the Email from my application but problem
I'm using the following code to send an email with attachments: $mime_boundary = <<<--==+X[.md5(time()).];
I tried to send an email using the following code: MailMessage message = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.