• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Message: Undefined variable: data when trying to send HTML mail

#1
[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!!

#2
[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.

#3
[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 = "testemail@testing.com";
$this->email->from('testemail@anotherdomain.com', '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();

#4
[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.

#5
[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.

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

#7
[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'] = 'someuser@mydomain.com';
$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('welcome@mydomain.com', 'The Management');
        $this->email->to('some@email.com');
        
        $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();    
    }

#8
[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!

#9
[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.

#10
[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('your@your-site.com');
$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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.