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
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
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.