Advertisement
pedroboreio

Untitled

Feb 28th, 2019
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1.  
  2. function register()
  3. {
  4. if(isset($_POST['register'])){
  5.  
  6. $this->form_validation->set_rules('username','Username','required|is_unique[accounts.Username]');
  7. $this->form_validation->set_rules('email','Email','required|is_unique[accounts.Email]');
  8. $this->form_validation->set_rules('nomeforum','nomeforum','required|is_unique[accounts.nomeforum]');
  9. $this->form_validation->set_rules('password','Password','required');
  10. //
  11. if($this->form_validation->run () == true){
  12. $data = array(
  13. 'username'=>$_POST['username'],
  14. 'email'=>$_POST['email'],
  15. 'nomeforum'=>$_POST['nomeforum'],
  16. 'password'=>strtoupper(hash('whirlpool',$_POST['password']))
  17.  
  18. );
  19. $this->db->insert('accounts',$data);
  20. $this->session->set_flashdata('success_msg', 'Sua conta foi criada com sucesso.');
  21. try {
  22. $this->send_email($email, $subject, $message)
  23. } catch (Exception $e) {
  24. $this->set_error($e->getMessage());
  25. }
  26. redirect("painel/register");
  27.  
  28.  
  29. }
  30.  
  31.  
  32. }
  33. $this->load->view("painel/register");
  34. }
  35.  
  36.  
  37. public function send_mail($to, $subject, $body, $from = NULL, $from_name = NULL, $attachment = NULL, $cc = NULL, $bcc = NULL) {
  38.  
  39. try {
  40. $mail = new PHPMailer;
  41. $mail->isSMTP();
  42. // $mail->SMTPDebug = 1;
  43. $mail->Host = "smtp.gmail.com";
  44. $mail->SMTPAuth = true;
  45. $mail->Username = $emailusername;
  46. $mail->Password = $emailpassword;
  47. $mail->Port = 465;
  48.  
  49. if ($from && $from_name) {
  50. $mail->setFrom($from, $from_name);
  51. $mail->setaddReplyToFrom($from, $from_name);
  52. } elseif ($from) {
  53. $mail->setFrom($from, $this->site_name);
  54. $mail->addReplyTo($from, $this->site_name);
  55. } else {
  56. $mail->setFrom($this->default_email, $this->site_name);
  57. $mail->addReplyTo($this->default_email, $this->site_name);
  58. }
  59.  
  60. $mail->addAddress($to);
  61. if ($cc) { $mail->addCC($cc); }
  62. if ($bcc) { $mail->addBCC($bcc); }
  63. $mail->Subject = $subject;
  64. $mail->isHTML(true);
  65. $mail->Body = $body;
  66. if ($attachment) {
  67. if (is_array($attachment)) {
  68. foreach ($attachment as $attach) {
  69. $mail->addAttachment($attach);
  70. }
  71. } else {
  72. $mail->addAttachment($attachment);
  73. }
  74. }
  75.  
  76. if (!$mail->send()) {
  77. throw new Exception($mail->ErrorInfo);
  78. return FALSE;
  79. }
  80. return TRUE;
  81. } catch (phpmailerException $e) {
  82. throw new Exception($e->errorMessage());
  83. } catch (Exception $e) {
  84. throw new Exception($e->getMessage());
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement