0

Below is my function in controller where I included phpmailer/PHPMailerAutoload.php But when I comment $mail = new PHPMailer this i dont get any error.

Help me Please!

     function register_user() {

        $company_name = $this->input->post('company_name');
        $name = $this->input->post('name');
        $gstn_number = $this->input->post('gstn_number');
        $mobile = $this->input->post('mobile');
        $email = $this->input->post('email');
        $password = $this->input->post('password');

        if (isset($_POST["register"])) {

            $status = $this->common_model->executeNonQuery("INSERT INTO `temp_register`(`company_name`,`name`,`gstn_number`,`mobile`,`email`,`password`) VALUES ('$company_name','$name','$gstn_number','$mobile','$email','$password')");
            if ($status) {

            $mail = new PHPMailer;

            $mail->SMTPDebug = 3;
            $mail->setFrom($email, 'example');
            $mail->addAddress($mail_to, 'ac');
            $mail->Subject  = 'Request Approval Sent From User';
            $mail->Body = "Please Approve My Request!";
            $mail->send();
                echo "<script>
            alert('You have successfully requested for registration! You will be notified when request is approved, Thanks!');
            window.location.href='some_location';
            </script>";
            } else {
                echo "<script>
            alert('Problem While Requesting Please Try Again!');
            window.location.href=''location';
            </script>";
            }
        }
    }
  • 3
    What error do you get? How is it not working? – John Conde Jan 17 '18 at 17:46
  • 2
    Your code is likely vulnerable to [**SQL injection**](https://en.wikipedia.org/wiki/SQL_injection) attacks. You should use prepared statements with bound parameters, via either the [**mysqli**](https://secure.php.net/manual/en/mysqli.prepare.php) or [**PDO**](https://secure.php.net/manual/en/pdo.prepared-statements.php) driver. [**This post**](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) has some good examples. – Alex Howansky Jan 17 '18 at 17:51
  • 3
    **Never** store plain text passwords. Instead use [`password_hash()`](http://us3.php.net/manual/en/function.password-hash.php) and [`password_verify()`](http://us3.php.net/manual/en/function.password-verify.php). If you're using a version of PHP prior to 5.5, do **not** use MD5 or SHA1 to hash passwords. Instead you can use [this compatibility pack](https://github.com/ircmaxell/password_compat). – Alex Howansky Jan 17 '18 at 17:51
  • Page is not working error i am getting. – aditya aundhekar Jan 17 '18 at 17:51
  • The phpmailer/PHPMailerAutoload.php file is in libraries folder already – aditya aundhekar Jan 17 '18 at 17:53
  • If anyone finds anything wrong in code please tell me because it is important function for me and it is not working on live server – aditya aundhekar Jan 17 '18 at 18:04
  • Codeigniter has a built in email library https://www.codeigniter.com/user_guide/libraries/email.html –  Jan 17 '18 at 18:13
  • @user4419336 I loaded library then i wrote following code but mail was not sent $this->email->from('rakesh3744@gmail.com', 'Your Name'); $this->email->to('adityaaundhekar311@gmail.com'); $this->email->cc('another@another-example.com'); // $this->email->bcc('them@their-example.com'); $this->email->subject('Email Test'); $this->email->message('Testing the email class.'); $this->email->send(); – aditya aundhekar Jan 17 '18 at 18:24
  • Not just that - there is [a CodeIgniter module that wraps PHPMailer](https://github.com/ivantcholakov/codeigniter-phpmailer), so you don't need to do it yourself. – Synchro Jan 17 '18 at 18:24
  • Please help me through the current code i do not want to use codeigniter library – aditya aundhekar Jan 17 '18 at 18:27
  • If your using local host might need to set up the backend sendmail https://www.youtube.com/watch?v=TO7MfDcM-Ho –  Jan 17 '18 at 18:39
  • @adityaaundhekar you'll have to learn how to turn on error reporting so you can see the errors. You'll also need to describe the expected behavior and the behavior you're getting. – Goose Jan 17 '18 at 22:53

0 Answers0