⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Send email



maru
  • profile picture
  • Member

Posted 25 February 2013 - 21:47 PM

Hi everyone!

 

I have a CRUD "clientes" and I added a button "email", when I click on it I would like to send an email with a username and a password

 

here is my button

 

$crud->add_action('Email''''pendientes/pendientes_v/enviarmail''ui-icon-plus'); 

 

and then the function

 

 function enviarmail($id
    {     
    
$this->load->model('email_model''email'); 
    
$this->email($id); 
    } 

 

 

then I created a model based on an example from codeigniter

 

class Email_model extends CI_Controller 
{   
     
$this->load->library('email'); 

    
$this->email->from('your@example.com''Demo'); 
    
$this->email->to('someone@example.com');  
     
    
$this->email->subject('Email Test'); 
    
$this->email->message('Testing the email class.');     
     
    
$this->email->send(); 
     
    echo 
$this->email->print_debugger(); 

 

 

but this $this->email->to('someone@example.com'); must be a variable because every row has a different email and how can I do to add username and password in the body of this email?

 

hope can help me, thank u so much in advance!

regards!

 


victor
  • profile picture
  • Member

Posted 26 February 2013 - 07:52 AM

1)selcet user data from db by id.
2)set email address using user data: $this->email->to($data['email']);
3)send email

maru
  • profile picture
  • Member

Posted 27 February 2013 - 02:07 AM

Victor, thanks for your answer!

 

I have this error Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /home/oscar/public_html/crud/application/models/email_model.php on line 5

 

 

in my controller

 

 

 

 function enviaremail($id)    {
    $this->load->model('email_model', 'sendmail');
  
    $this->sendemail($id);
    }
 

 

 
in my model email_model.php
 

 

<?php


class Email_model extends CI_Controller
{  
     $this->load->library('email');


    $this->email->from('mymail@server.com', 'Demo');
    $this->email->to($data['email']);  
    
    $this->email->subject('Email Test');
    $this->email->message('Testing the email class.');    
    
    $this->email->send();
    
    echo $this->email->print_debugger();


}
 

 

this is the line 5   $this->load->library('email');


victor
  • profile picture
  • Member

Posted 27 February 2013 - 06:32 AM

Read about php classes. your class is wrong.
and read CI user guard.

maru
  • profile picture
  • Member

Posted 15 March 2013 - 02:34 AM

I tried with this in my controller

 

 

 

  function copyrows($id)
    {    
    $this->load->model('cliente_model', 'client');
    
    $clientInfo = $this->client->getInfo($cliente_id);    
    
    $this->email->from('myemail@gmail.com', 'Demo'); 
    $this->email->to($clientInfo['email']);  
        
    $this->email->subject('Email Test'); 
    $this->email->message('Hola tu usuario es ' . $clientInfo['email'] . ' y tu contraseña es ' . $clientInfo['clave']);     
        
    $this->email->send(); 
        
    echo $this->email->print_debugger();    
        
    }
 

 

and in my model

 

 

 

<?php


class Cliente_Model extends CI_Model{


public function getInfo($client_id){
    return array('email' => $email,'clave' => $clave);
}
}
 

 

I wrote my email to test return array('email' => 'myemail@gmail.com','clave' => $clave); and I receive it but when I try with variables are empty.


maru
  • profile picture
  • Member

Posted 18 March 2013 - 21:36 PM

any help please ?  :(

I couldn't find why my variables are empty.


victor
  • profile picture
  • Member

Posted 18 March 2013 - 21:42 PM

public function getInfo($client_id){


return array('email' => $email,'clave' => $clave);

}

 

where do you use $client_id in this function?

 

 

if you  showed this code as example I have second question for you:

 

 

function copyrows($id)
{
$this->load->model('cliente_model', 'client');

$clientInfo = $this->client->getInfo($cliente_id);

.....

 

what value your variable "$cliente_id" has?


maru
  • profile picture
  • Member

Posted 18 March 2013 - 21:44 PM

$cliente_id it suppose take the id from my table clientes


victor
  • profile picture
  • Member

Posted 18 March 2013 - 21:46 PM

show, please, full controllers code


victor
  • profile picture
  • Member

Posted 18 March 2013 - 21:47 PM

and model too


maru
  • profile picture
  • Member

Posted 18 March 2013 - 21:54 PM

my controller

 

 

 

<?php


if (!defined('BASEPATH'))
    exit('No direct script access allowed');


class Pendientes extends CI_Controller
{


    function __construct()
    {


    parent::__construct();


    $this->template->set_layout('layout.php');
    $this->load->database();
    $this->load->library('grocery_crud');
    $this->load->library('email'); 
    $this->load->helper('url');
    }


    function index()
    {
    
    }


    function pendientes_v()
    {
    if ($this->uri->segment(3) == "copyrows")
    {
        $row_id = $this->uri->segment(4);
        $this->copyrows($row_id);
        redirect('pendientes/pendientes_v');
    }


    $this->load->view('layouts/header');
    $this->load->view('layouts/menu');
    try
    {
        $crud = new grocery_CRUD();
        $crud->set_theme('datatables');
        $crud->set_table('pendientes');
        $crud->set_subject('Pendientes');
        $crud->required_fields(
            'nombre', 'email'
        );
        $crud->columns(
            'id', 'nombre', 'email', 'empresa', 'cuit', 'direccion', 'telefono', 'clave'
        );


        $crud->add_action('Enviar', '', 'pendientes/pendientes_v/copyrows', 'ui-icon-plus');
        $output = $crud->render();
        $this->load->view('pendientes/pendientes_v', $output);
    }
    catch (Exception $e)
    {
        show_error($e->getMessage() . ' --- ' . $e->getTraceAsString());
    }


    $this->load->view('layouts/footer');
    }


    function copyrows($id)
    {
    $this->load->model('standby_model', 'standby');
    $this->load->model('cliente_model', 'client');
    $this->load->model('customer_model', 'customers');
    
    $clientInfo = $this->client->getInfo($client_id);    
    
    $this->email->from('myemail@gmail.com', 'Demo'); 
    $this->email->to($clientInfo['email']);  
        
    $this->email->subject('Email Test'); 
    $this->email->message('Hola tu usuario es ' . $clientInfo['email'] . ' y tu contraseña es ' . $clientInfo['clave']);     
        
    $this->email->send(); 
        
    echo $this->email->print_debugger();    
    
    $this->customers->insert($id);
    $this->standby->delete($id);
    }


}



 

 

my model cliente_model.php
 

 

<?php


class Cliente_Model extends CI_Model{




public function getInfo($client_id){
    return array('email' => $email,'clave' => $clave);
    
}
}

 

 

 

the structure of my table 

 'id', 'nombre', 'email', 'empresa', 'cuit', 'direccion', 'telefono', 'clave'

 

 

errors

 

Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.
From: "Demo"
Return-Path:
Reply-To: "myemail@gmail.com"
X-Sender: myemail@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <51478bcb599c0@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
=?utf-8?Q?Email_Test?=
Hola tu usuario es y tu contraseña es@gmail.com>@gmail.com>@gmail.com>


A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/oscar/public_html/crud/system/core/Exceptions.php:185)

Filename: core/Common.php

Line Number: 438


victor
  • profile picture
  • Member

Posted 18 March 2013 - 22:00 PM

public function getInfo($client_id){


return array('email' => $email,'clave' => $clave);


}

where do you use the $client_id in this function?


victor
  • profile picture
  • Member

Posted 18 March 2013 - 22:07 PM

function copyrows($id)
{
$this->load->model('standby_model', 'standby');
$this->load->model('cliente_model', 'client');
$this->load->model('customer_model', 'customers');

$clientInfo = $this->client->getInfo($client_id);

 

where do you get  "$client_id" value in this code?

 

for example: 

$client_id = ......

$clientInfo = $this->client->getInfo($client_id);

 

in your case $client_id is undefined (null).

then you use it :

$clientInfo = $this->client->getInfo(null);

what result do you want to get using NULL ?

yes! You get NULL


maru
  • profile picture
  • Member

Posted 18 March 2013 - 22:09 PM

sorry return array('id' => $cliente_id, 'email' => $email,'clave' => $clave);

but I have the same error


victor
  • profile picture
  • Member

Posted 18 March 2013 - 22:10 PM

/topic/1420-send-email/#entry6396


maru
  • profile picture
  • Member

Posted 18 March 2013 - 22:11 PM

I tried also with 'id' but it's the same


maru
  • profile picture
  • Member

Posted 18 March 2013 - 22:16 PM

thanks for your explanation Victor, I understand I am receiving a null value, how should I get the id cliente?


victor
  • profile picture
  • Member

Posted 18 March 2013 - 22:20 PM

you can use id for that.

 

try to do this:

 

function copyrows($id)
{

echo $id;

exit;

......

 

what result do you have?


maru
  • profile picture
  • Member

Posted 18 March 2013 - 22:28 PM

I receive the id number of the client I choose

 

 

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: email

Filename: models/cliente_model.php

Line Number: 9

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: clave

Filename: models/cliente_model.php

Line Number: 9

27


victor
  • profile picture
  • Member

Posted 18 March 2013 - 22:34 PM

Yes! Because you don't use $email!

what value does $email has?

 

 

public function getInfo($client_id){

return array('email' => $email,'clave' => $clave);

}

where do you get value of $email variable in this function?

before using you need set variables value: 

$email = ....