Welcome Guest, Not a member yet? Register   Sign In
auto email
#1

[eluser]learning_php[/eluser]
Hi,

I have created a very basic login system where users have to register to gain access to certain areas. The code below moves them from one table to another.
Code:
function updatemembers()
    {
        $id = $_POST["id"];
        $approved = $_POST["approved"];
        
        if($approved = "Yes") {
            $this->db->query("insert into members (select * from pending_members where id = " . $id . ")");
            $this->db->query("delete from pending_members where id = " . $id );
            $this->load->view('update_data_view');
        
            
        }
        else if($approved = "No"){
            
            $this->db->query("delete from pending_members where id = " . $id );
            $this->load->view('update_data_view');

        }
    }

does anyone know how difficult it is to send a auto email to either confirm or reject a user membership request?
#2

[eluser]Mike Ryan[/eluser]
Hi,

If you just want to let the user know if their request was accepted or denied, you could do this quite easily with the Email Class.

Code:
//snip
$this->load->library('email');
$this->email->from('[email protected]', 'Your Name');
$this->email->to('[email protected]');

if($approved = "Yes") {
    $this->db->query("insert into members (select * from pending_members where id = " . $id . ")");
    $this->db->query("delete from pending_members where id = " . $id );
    
    $this->email->subject('Request confirmed');
    $this->email->message('...');
    $this->email->send();
    $this->load->view('update_data_view');
}
else if($approved = "No"){
    
    $this->db->query("delete from pending_members where id = " . $id );
    $this->load->view('update_data_view');
    $this->email->subject('Request denied');
    $this->email->message('...');
    $this->email->send();
}

You could extend the email class with "send_confirmed" and "send_denied" functions to move the email body/subject out of the controller logic if you wanted that level of abstraction.
#3

[eluser]Dam1an[/eluser]
Instead of moving users between tables, could you not just have a boolean field for pending?
#4

[eluser]learning_php[/eluser]
Hi,

I have changed the function to this:

Code:
function updatemembers()
    {
        $this->load->library('email');
        $id = $_POST["id"];
        $approved = $_POST["approved"];
        $email = $_POST["email"];
        $this->email->from('[email protected]');
        $this->email->to($email);

        
        
        if($approved = "Yes") {
            $this->db->query("insert into members (select * from pending_members where id = " . $id . ")");
            $this->db->query("delete from pending_members where id = " . $id );
            $this->email->from('[email protected]');
            $this->email->to($email);
                $this->email->subject('Membership confirmed');
                 $this->email->message('...');
                $this->email->send();
            $this->load->view('update_data_view');
        
            
        }
        else if($approved = "No"){
            
            $this->db->query("delete from pending_members where id = " . $id );
            $this->load->view('update_data_view');
                $this->email->subject('Membership denied');
                $this->email->message('...');
                $this->email->send();

        }

But I get the error:
[code]
A PHP Error was encountered

Severity: Notice

Message: Undefined index: email

Filename: controllers/homepage.php

Line Number: 53
[/code
#5

[eluser]Dam1an[/eluser]
Can you maybe tell us which line is number 53? As there are numerous 'email' variables
#6

[eluser]learning_php[/eluser]
sorry
Code:
$email = $_POST["email"];
#7

[eluser]Dam1an[/eluser]
And whats the view for the form?
Cause it would appear you don;t havea field named email?
#8

[eluser]learning_php[/eluser]
This is the form i am using:

Code:
<?= form_open('homepage/update_register') ?>
  First Name: <input type="text" name="first_name" id="first_name" value="" Autocomplete="off" /><br />
  <br />
  Last Name: &lt;input type="text" name="last_name" id="last_name" value="" Autocomplete="off" /&gt;&lt;br />
  <br />
  Username: &lt;input type="text" name="username" id="username" value="" Autocomplete="off" /&gt;&lt;br />
  <br />
  Password: &lt;input type="password" name="password" id="password" value="" Autocomplete="off" /&gt;&lt;br />
   <br />
  Email: &lt;input type="text" name="email" id="email" value="" Autocomplete="off" /&gt;&lt;br />
  <br />
  &lt;input type="submit" value="register"  /&gt;

&lt;?=form_close() ?&gt;
#9

[eluser]learning_php[/eluser]
Hi,

Sorry forgot to add this. it'a the form to decide to approve members or not:

Code:
&lt;?PHP                                
$sql="select * FROM pending_members";
$Q = $this->db->query($sql);
foreach ($Q->result() as $row):?&gt;
<table border="0">
     <tr>
         <td width="25px" nowrap="ON">&lt;?=$row->id?&gt;</td>
         <td width="150px" nowrap="ON" >&lt;?=$row->first_Name?&gt;</td>
         <td width="150px" nowrap="ON">&lt;?=$row->last_Name?&gt;</td>
         <td width="150px" nowrap="ON">&lt;?=$row->email?&gt;</td>
        <td width="150px" nowrap="ON">&lt;?=$row->username?&gt;</td>
        <td width="80px" nowrap="ON">&lt;?=$row->relationship?&gt;</td>
        
        &lt;?=form_open('homepage/updatemembers');?&gt;
        <td width="50px" nowrap="ON">
            <select name="approved">
            <option value=""></option>
              <option value="Yes">Yes</option>
              <option value="No">No</option>
              </select>
          </td>
          &lt;input type="hidden" name="id" value="&lt;?=$row-&gt;id?&gt;"/>
          &lt;input type="hidden" name="email" value="&lt;?=$row-&gt;email?&gt;"/>
        <td width="150px" >&lt;input type="submit" value="update"  /&gt;&lt;/td>
        
         &lt;?=form_close() ?&gt;
    </tr>
</table>
&lt;?PHP endforeach;?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB