-1

while sending email i am using emailformat='both' but i am sending email without using template.

$Email->reset();
$Email->emailFormat('both');
$Email->to($to);
$Email->send($body);

in original email i am not getting the plain text :-

--alt-82207de3b13b81a697e6c7c6db145af2
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

<div>​<br>Hi<br><br>Soon you will reach the action limit. To keep yourself updated please pay the payment.<br><br> Happy to&nbsp; have you<br><br>Thanks,<br>Kioui Apps Team<br>​</div>


--alt-82207de3b13b81a697e6c7c6db145af2
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<div>​<br>Hi<br><br>Soon you will reach the action limit. To keep yourself updated please pay the payment.<br><br> Happy to&nbsp; have you<br><br>Thanks,<br>Kioui Apps Team<br>​</div>
Shahzad Barkati
  • 2,532
  • 6
  • 25
  • 33
user3744854
  • 43
  • 1
  • 4

1 Answers1

1

CakePHP does not offer such functionality out of the box.

Theoretically you should be able to achieve this without templates by using your own custom render (view) class that ignores the templates and just transforms the content.

However that's kinda hacky, it would be way easier to simply create two basic templates that do not add content on their own, but just echo/transform the $content view var, which will hold whatever you pass to CakeEmail::send().

A simple example:

Emails/html/template-name.ctp

echo $content;

Emails/text/template-name.ctp

echo html_entity_decode(strip_tags($content), ENT_QUOTES, Configure::read('App.encoding'));

Note that this just a very basic example that should demonstrate the concept, it is not a proper HTML to Text conversion in any way, you should use/build a dedicated HTML to Text converter that properly sanitizes and transforms the input!

See for example Converting HTML to plain text in PHP for e-mail

Community
  • 1
  • 1
ndm
  • 59,784
  • 9
  • 71
  • 110