PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 19, 2022

[FIXED] send email after filling a form

 February 19, 2022     codeigniter, email, mysql, php     No comments   

Issue

I'm trying to create in a website in codeigniter a functionality to always that someone fill a Form it will create an entry in my database and send an email with that information.

Now I already have everything so it goes to the database but i need to know how to sent the email.

<div class="col-md-7 contact-form">
            <form method="post" action="contact" >
                <input placeholder="Assunto" type="text" value="{$nome}" name="nome" >
                <input placeholder="Email" type="text" value="{$email}" name="email" >
                <textarea placeholder="Message" type="text" value="{$content}" name="content"></textarea>
                <input type="submit" value="SEND">
            </form>
        </div>

Thank You!


Solution

You can use CodeIgniter built-in email library

Email Class

In your case, i think its better to give "name" attribute to the submit button:

<input type='submit' name='somesubmitbutton' value='SEND' />

And then using it to verify before sending email:

if(!is_null($this->input->post("somesubmitbutton"))){
 $email  = $this->input->post("email");
 $name   = $this->input->post("name");
 $config = [
          'mailtype'  => 'html',
          'charset'   => 'utf-8',
          'protocol'  => 'smtp',
          'smtp_host' => 'smtp.gmail.com',
          'smtp_user' => 'email@gmail.com', // You must turn ON "Allow less secure apps" in this gmail account (open https://myaccount.google.com/lesssecureapps)
          'smtp_pass'   => 'emailpassword',
          'smtp_crypto' => 'ssl',
          'smtp_port'   => 465,
          'crlf'    => "\r\n",
          'newline' => "\r\n"
            ];

 $this->load->library('email',$config);
 $this->email->from('email@gmail.com', 'Sender Name');

 // EMAIL TO
 $this->email->to($email);

 $this->email->subject("Hello!");
 $this->email->message("Good afternoon $name!");
 $this->email->send();
}


Answered By - Rahmad
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing