• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Load information into email message.

Hy guys.

I need to send email messages that have some default text and some strings loaded into it, like $name and $last_name, something like this:

message = '
Dear '.$name.' '.$last_name.',<br>
Você está recebendo este e-mail pois esse endereço<br>
foi cadastrado para o projeto SINUS 2012.<br>
Se você não se registrou, por favor, desregarde esse email.<br>

The email message is hardcoded inside my controller, but I would like to put the email message into a text file and load it from the controller.

This is working OK, but the $name and $last_name don't get loaded, the message stays
Dear '.$name.' '.$last_name.',<br>
, the variables do not get changed.

Is there any way to do this? Load the email message from a file and have the variables chaged?

My email function is this:

function sendEmailConf($name,$last_name,$email){
$message = read_file('./attachments/email_actv.txt');


Email Templates with CodeIgniter

function signup()

    $data = array(
        'some_var_for_view' => 'Some Value for View'

    $htmlMessage = $this->parser->parse('user/email/signup_html', $data, true);
    $txtMessage  = $this->parser->parse('user/email/signup_txt',  $data, true);

    #send the message
    $this->email->from('[email protected]', 'CSSNinja');
    $this->email->subject('Account Registration Confirmation');



[eluser]Iszuddin Ismail[/eluser]
I would use the view. You simply create a PHP file and store it in /view folder, just like how you would normally create one. And you can use the view and generate the output as a string instead of loading the view. Here's a brief example.

// prepare email data for email_body.php view
$email_data['name'] = 'John';
$email_data['lastname'] = 'Doe';

// load email_body.php view file and pass as string data to variable
$email_body = $this->load->view('email_body', $email_data, true);

$this->email->from('[email protected]', 'CSSNinja');
$this->email->subject('Account Registration Confirmation');
$this->email->message($email_body); // use $email_body from previous

[eluser]Bhashkar Yadav[/eluser]
both procedures are good! Smile

Very nice, guys!

Thanks for the replies! Helped me a lot!

Now I'm facing a new issue.

My sendEmail function is like this:

function sendEmail($nome,$sobrenome,$email,$subject,$emailText){

            $data = array(
            'nome' => $nome,
            'sobrenome' => $sobrenome,
            'email' => $email,
            'hash' => $hash
      $htmlMessage =  $this->parser->parse("../../attachments/$emailText", $data, true);

The $nome, $sobrenome and $email are send direcly from the Database, with a simples get() and then $query->name, $query->last_name and $query->email.

The email is totally OK, working very well, but, if any name or last_name have these types of characters: á, à, é, è, etc, those characters get chagend, like:

Claudio Donaté is changed to Claudio Donaté.

Weird thing is that the email text itseft have a few of these types of characters, and they are working fine.

Only the $data that is being parsed is changing.

How can I correct this?

My email text is as follows:

&lt;meta http-equiv="Content-Type" content="text/html charset=UTF-8" /&gt;
{nome} {sobrenome},<br>
Sua inscrição para a SINUS 2012 foi recebida com successo.<br>
Em breve você receberá resposta sobre a efetivação da inscrição<br>
e as instruções para o pagamento.<br>
Qualquer dúvida favor entrar em contato com a organização pelo e-mail:<br>
[email protected]<br>
Atenciosamente, <br>
<b>Organização SINUS 2012</b>


try using htmlentities..

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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