CodeIgniter Forums
Message: Undefined variable: data when trying to send HTML mail - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Message: Undefined variable: data when trying to send HTML mail (/showthread.php?tid=3559)



Message: Undefined variable: data when trying to send HTML mail - El Forum - 10-10-2007

[eluser]spheroid[/eluser]
I'm able to send email by defining my HTML mail message within the code directly. But according to another post on the forums, I realized I could load a view. When I do I get this message:

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: data

Filename: controllers/user.php

I'm loading my email config variables from email.php. Here is the code to load the view/create the email (partial):

Code:
$this->email->subject('Email Test. Is this your email address: '.$sendto);
$message = $this->load->view('email_welcome_test', $data, TRUE);
$this->email->message($message);
$this->email->send();

What can I do to fix this? Thanks in advance!!


Message: Undefined variable: data when trying to send HTML mail - El Forum - 10-10-2007

[eluser]Derek Allard[/eluser]
Ah, probably stealing my bad code are you Wink (joking)

Above the code I posted I had

Code:
$data['title'] = "some text";
$data['somevar'] = "just some var";

If you don't think you'll need to pass it any info, you could always just do
Code:
$data = new array();

and that would satisfy the function.


Message: Undefined variable: data when trying to send HTML mail - El Forum - 10-10-2007

[eluser]spheroid[/eluser]
Thanks for the quick reply! Yeah, for the code put it on my tab (call me Norm!). Now I have this, this is the only code in one controller function to test it out. I get a blank page, and no debug results. Hmm. What else could it be?

Code:
$this->load->library('email');
$data = new array();
$sendto = "[email protected]";
$this->email->from('[email protected]', 'Hey!!!');
$this->email->to($sendto);        
$this->email->subject('Email Test. Is this your email address: '.$sendto);    
$message = $this->load->view('email_welcome_test', $data, TRUE);
$this->email->message($message);
$this->email->send();    
echo $this->email->print_debugger();



Message: Undefined variable: data when trying to send HTML mail - El Forum - 10-10-2007

[eluser]Derek Allard[/eluser]
I'd start eliminating things. Can you do $this->email->message('foo'); successfully? that would at least reduce what might be happening.


Message: Undefined variable: data when trying to send HTML mail - El Forum - 10-10-2007

[eluser]spheroid[/eluser]
That works. I'm still trying to eliminate things. When I do use 'foo' instead, the debug shows it's sending as text, not html.


Message: Undefined variable: data when trying to send HTML mail - El Forum - 10-10-2007

[eluser]Derek Allard[/eluser]
So um... have you configured it to send as html Wink


Message: Undefined variable: data when trying to send HTML mail - El Forum - 10-10-2007

[eluser]spheroid[/eluser]
I thought I did. I checked my config file, saved as "email.php" in my config folder. Saving as "Email.php" doesn't work (debug yields nothing).

config/email.php

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

$config['protocol'] = 'sendmail';
$config['smtp_host'] = 'mail.mydomain.com';
$config['smtp_user'] = '[email protected]';
$config['smtp_pass'] = 'somethinggoeshere';
$config['mailtype'] = 'html';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;

?>

function from my controller

Code:
function hey()
    {
        $this->load->library('email');
        
        $data = array();

        $this->email->from('[email protected]', 'The Management');
        $this->email->to('[email protected]');
        
        $this->email->subject('Email Test. Is this your email address: ');
            
        $message = $this->load->view('email_welcome_test', $data, TRUE);
            
        $this->email->message($message);
    
        $this->email->send();    
        
        echo $this->email->print_debugger();    
    }



Message: Undefined variable: data when trying to send HTML mail - El Forum - 10-10-2007

[eluser]spheroid[/eluser]
Strange. I modified the Email.php file in the system/libraries folder to html and it worked. Then I changed back to text in that file. I moved the "email.php" file from my application/config to application/libraries folder, and since it didn't work, I moved it back to application/config, and renamed to Email.php. Now it works. Ugh. Another one of those issues where I don't know what caused it. Thanks for your help! Loving CI!


Message: Undefined variable: data when trying to send HTML mail - El Forum - 10-10-2007

[eluser]Derek Allard[/eluser]
Wow, I love self-healing applications Wink Glad you got it resolved, and happy to help in whatever little way I could.


Message: Undefined variable: data when trying to send HTML mail - El Forum - 11-20-2007

[eluser]vinod_ci[/eluser]
hello guys i have same problem
i have send mail of html type


$message =$this->load->view('with-ads','');
$config['wordwrap'] = false;
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->to($to);
$this->email->from('[email protected]');
$this->email->subject('Here is your info '.'gggdf');
$this->email->message($message);


But i can't see any table in email

only one statement like this
--B_ALT_42eaae77d421c--

please reply fast