Welcome Guest, Not a member yet? Register   Sign In
Load information into email message.
#1

[eluser]cdonate[/eluser]
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:

Code:
message = '
<br>
Dear '.$name.' '.$last_name.',<br>
<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>
<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
Code:
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:

Code:
function sendEmailConf($name,$last_name,$email){
  
$this->load->helper('file');
  
$message = read_file('./attachments/email_actv.txt');

Thanks!!!
#2

[eluser]InsiteFX[/eluser]
Code:
Email Templates with CodeIgniter

function signup()
{
    $this->load->library('parser');

    $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->to($this->input->post('email_address'));
    $this->email->subject('Account Registration Confirmation');
    $this->email->message($htmlMessage);

    $this->email->set_alt_message($txtMessage);

    $this->email->send();
}
#3

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

Code:
// 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->to($this->input->post('email_address'));
$this->email->subject('Account Registration Confirmation');
$this->email->message($email_body); // use $email_body from previous
#4

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

[eluser]cdonate[/eluser]
Very nice, guys!

Thanks for the replies! Helped me a lot!
#6

[eluser]cdonate[/eluser]
Now I'm facing a new issue.

My sendEmail function is like this:

Code:
function sendEmail($nome,$sobrenome,$email,$subject,$emailText){
  
$this->load->library('parser');
  

            $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:

Code:
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html charset=UTF-8" /&gt;
&lt;title&gt;&lt;/title>
&lt;/head&gt;
&lt;body&gt;
<br>        
{nome} {sobrenome},<br>
<br>
Parabéns!<br>
------------------------------<wbr>------------------<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>
------------------------------<wbr>------------------<br>
<br>
Atenciosamente, <br>
<br>
<b>Organização SINUS 2012</b>
<br>
&lt;/body&gt;
&lt;/html&gt;

Thanks!
#7

[eluser]Unknown[/eluser]
try using htmlentities..




Theme © iAndrew 2016 - Forum software by © MyBB