Welcome Guest, Not a member yet? Register   Sign In
Email Template
#1

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
Reply
#2

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

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;
Reply
#4

(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>
Reply
#5

(This post was last modified: 03-30-2021, 04:53 AM by InsiteFX.)

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB