Welcome Guest, Not a member yet? Register   Sign In
send post form data through email class
#1

[eluser]swgj19[/eluser]
Codeigniter version 2.0.
Hosting: Godaddy.com

I am working on a login/register script with a password retieval function. Currently I am on the part of the user entering their email in the form. When they hit submit, the controller email.php kicks in to send an email to the user. Now I am able to send a normal email by using a regular email address. However, when I try to pass in the posted data in a variable (the users email address) an email is not sent with no errors.

does not work
Code:
$this->email->to("$email");
does work
Code:
$this->email->to("[email protected]");


If someone has the time, please let me know where I am missing it. Thanks.
Code:
<?php

//Sends email with gmail

class Email extends CI_Controller
{
  
  function __construct()
  
   {
     parent::__construct();
   }
  function index(){

  
    $config = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'ssl://smtp.googlemail.com',
      'smtp_port' => 465,
      'smtp_user' => '[email protected]',
      'smtp_pass' => '********',
      'charset' => "utf-8",
'mailtype' => "html",
'newline' => "\r\n"

    );

    $this->load->library('email', $config);
    $this->form_validation->set_rules('email_address', 'Email', 'trim|required');
$email = $this->input->get_post('email_address');
    $this->email->set_newline("\r\n"); /* for some reason it is needed */

    $this->email->from('[email protected]', 'Aditya Lesmana Test');
    $this->email->to("$email");
    $this->email->subject('This is an email test');
    $this->email->message('it is working Darling');

    if($this->email->send())
    {
      echo 'Your email was sent';
    }
    else
    {
      show_error($this->email->print_debugger());
    }

    }
}

Also,here is the controller that calls the email controller above.

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Retrieve extends CI_Controller {

function index()
{
  $data['main_content'] = 'forgot_password';        //create new key 'main_content, which turns into a variable, pass in view you want to load
  $this->load->view('includes/template', $data);
}
function retrieve_password()
{  
  $this->load->model('membership_model');          //load membership model
  $query = $this->membership_model->retrieve();        //call method
  
  if($query) // if the user's credentials validated...      //if user's credentials are validated...
  {
   $data = array(               //then create new data equal to array
    'username' => $this->input->post('username'),      
               //add value to session
   );                  //is_logged_in is function in site controller
   $this->load->view('send_password_link');

// Email retrieve password link to users posted email

  //$this->load->library('email');

  redirect('email');  //redirect to email controller      
  }
  else // incorrect username or password
  {
  
  
   $this->index();
                //load index.php if login was not correct or nothing returned from db
  }

}
}
#2

[eluser]InsiteFX[/eluser]
Try this steve.
Code:
$this->email->to('"'.$email.'"');
#3

[eluser]swgj19[/eluser]
Hey Ray. Thanks. I tried it, but same result. It says my email was sent, but no email.
#4

[eluser]InsiteFX[/eluser]
Try it this way, it should take a list or an array.
Code:
$this->email->to($email);
#5

[eluser]swgj19[/eluser]
Same result. However, I did a var_dump($email). The result I get is bool(false). For some reason nothing is stored in the string from the post data it seems.
#6

[eluser]InsiteFX[/eluser]
Can you show your form for it?
#7

[eluser]swgj19[/eluser]
Code:
<h3>Forgot Your Password!</h3>
<fieldset>
<legend>Enter your email. Then press submit and follow the link in your email to get a new password.</legend>
&lt;?php
  
echo form_open('retrieve/retrieve_password');
echo form_input('email_address', set_value('email_address', 'Email Address'));


echo form_submit('submit', 'Send');
?&gt;

&lt;?php echo validation_errors('<p class="error">'); ?&gt;
</fieldset>
#8

[eluser]InsiteFX[/eluser]
Your missing the form_close

Code:
&lt;?php echo form_open('retrieve/retrieve_password');?&gt;

    <h3>Forgot Your Password!</h3>

    <fieldset>
        <legend>Enter your email. Then press submit and follow the link in your email to get a new password.</legend>
&lt;?php
    echo form_input('email_address', set_value('email_address', 'Email Address'));

    echo form_submit('submit', 'Send');
?&gt;
    </fieldset>
&lt;?php echo validation_errors('<p class="error">'); ?&gt;

&lt;?php echo form_close();?&gt;

Also I just noticed you are getting the email in the index but the form is posting to your retrive_password method.

Code:
private $email;

// in your retrive_password get the email address
$this->email = $this->input->post(your_email);

// then do this
$this->email->to($this->email);
#9

[eluser]InsiteFX[/eluser]
Just a minute and I'll write real quick!

You need to get the input email address in the retrive_password method.

Then it will need to be passed to the other controller.

I would just use one controller to do it all Steve...
#10

[eluser]swgj19[/eluser]
ok. I will do what you said and then get back with you. Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB