CodeIgniter Forums
Email Template - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Email Template (/showthread.php?tid=78561)



Email Template - Gehasi - 02-07-2021

Hey Guys, 

I'm relativly new in CI4 and im having problem with my email sending.

We have different emails we want to send from our website. Its working good the email are going out. But now we don't want to just send a email we want to have a template around the mail.

So I created a emailhead.php in the app/view folder and also a emailbody.php in the same folder and I just want to load it into my controller before the actual message.

I tried to do

Code:
$message = $this->load->view('emailhead.php');
$message .= 'The text of the email';
$message .= $this->load->view('emailfooter.php');

But I allways get an error 

ErrorException

Undefined property: App\Controllers\Email::$load

I appriciate all of your help, thanks


RE: Email Template - iRedds - 02-08-2021

I do not know what result you wanted to get using the CI3 code in CI4.
It's time to read the documentation


RE: Email Template - captain-sensible - 02-08-2021

a simple approach perhaps might be to assign the content of your template, which can contain html syntax to a controller class member via heredoc
Code:
<?php namespace App\Controllers;
class Sendmail extends Controller
{
      
   protected $totalMessage;    
   protected $headerTemplate=<<<EOT
blah
blah
EOT
//note no indent above
then in a method
Code:
$this->totalMessage= $this->headerTemplate." other string content".$this->headerFooter;


send $totalMessage;


RE: Email Template - buhosk - 03-29-2021

(02-07-2021, 08:16 PM)Gehasi Wrote: Hey Guys, 

I'm relativly new in CI4 and im having problem with my email sending.

We have different emails we want to send from our website. Its working good the email are going out. But now we don't want to just send a email we want to have a template around the mail.

So I created a emailhead.php in the app/view folder and also a emailbody.php in the same folder and I just want to load it into my controller before the actual message.

I tried to do

Code:
$message = $this->load->view('emailhead.php');
$message .= 'The text of the email';
$message .= $this->load->view('emailfooter.php');

But I allways get an error 

ErrorException

Undefined property: App\Controllers\Email::$load

I appriciate all of your help, thanks


Hello, i have the same trouble in ci3 you can use $this->load->view('template.php'); but not in ci4
you can do it this

PHP Code:
$email = \Config\Services::email();
        $parser = \Config\Services::parser();
        
        $config 
$this->datos_correo();
        $evento 'Activar cuenta';
        $texto 'Para terminar su proceso de registro haga click en la siguiente dirección o copiando la misma en su navegador.';
        $data = array( 'liga' => base_url().'index.php/registro/activacion/'.$id.'/'.$codigo'correo' => $correo'texto' => $texto'evento' => $evento );
        $body $parser->setData($data)->render('template/emails/correo');        
        
        $email
->initialize($config); 
        $email->setFrom($config['SMTPUser'], 'Sistema Reseller');
        $email->setTo($correo);        
        $email
->setSubject($evento);        
        $email
->setMessage($body);
        
$email->send(); 


in parser you template use pseudo-variables


Code:
<html>
<head>
        <title>{evento}</title>
</head>
<body>
        <h3>{evento}</h3>

       
                <h5>{texto}</h5>
                <p>{liga}</p>
       

</body>
</html>



RE: Email Template - InsiteFX - 03-30-2021

You can still do it but you have to use the view render.

PHP Code:
public function sendEmail()
{
   $view Services::renderer();

   $view->setData(['firstName'=>'George''lastName'=>'Boss']);

   $send $view->render('email_template');

   // you would assign this to your email
   echo $send;


Just an example.