php - Codeigniter Automatic welcome email on registration -
how can send welcome email registration system?
function register() { if(isset($_post['register'])){ $this->form_validation->set_rules('username','username','required|is_unique[accounts.username]'); $this->form_validation->set_rules('email','email','required|is_unique[accounts.email]'); $this->form_validation->set_rules('password','password','required'); // if($this->form_validation->run () == true){ echo 'form validate'; $data = array( 'username'=>$_post['username'], 'email'=>$_post['email'], 'password'=>strtoupper(hash('whirlpool',$_post['password'])) ); $this->db->insert('accounts',$data); $this->session->set_flashdata('success_msg', 'sua conta foi criada com sucesso.'); redirect("painel/register"); } }
how can send welcome email registration system?
after insert successful
try { $this->send_email($email, $subject, $message) } catch (exception $e) { $this->set_error($e->getmessage()); }
my send_mail function :
public function send_mail($to, $subject, $body, $from = null, $from_name = null, $attachment = null, $cc = null, $bcc = null) { try { $mail = new phpmailer; $mail->issmtp(); // $mail->smtpdebug = 1; $mail->host = "smtp.gmail.com"; $mail->smtpauth = true; $mail->username = $emailusername; $mail->password = $emailpassword; $mail->port = 465; if ($from && $from_name) { $mail->setfrom($from, $from_name); $mail->setaddreplytofrom($from, $from_name); } elseif ($from) { $mail->setfrom($from, $this->site_name); $mail->addreplyto($from, $this->site_name); } else { $mail->setfrom($this->default_email, $this->site_name); $mail->addreplyto($this->default_email, $this->site_name); } $mail->addaddress($to); if ($cc) { $mail->addcc($cc); } if ($bcc) { $mail->addbcc($bcc); } $mail->subject = $subject; $mail->ishtml(true); $mail->body = $body; if ($attachment) { if (is_array($attachment)) { foreach ($attachment $attach) { $mail->addattachment($attach); } } else { $mail->addattachment($attachment); } } if (!$mail->send()) { throw new exception($mail->errorinfo); return false; } return true; } catch (phpmailerexception $e) { throw new exception($e->errormessage()); } catch (exception $e) { throw new exception($e->getmessage()); } }
Comments
Post a Comment