Code snippets for symfony 1.x


Refine Tags

Snippets tagged "encode"

How to use sfMail to encode body of Japanese Email.

How to use sfMail to encode Body of Japanese Email.

The Japanese Email usually use ISO-2022-JP. But, I want to use UTF-8 of any Email template files. For example...

I create PROJECT_DIR/lib/myMail.class.php


class myMail extends sfMail
  public function setBody ($body)
    parent::setBody(mb_convert_encoding($body, "JIS", "UTF-8"));

OK, Use this class from your Action.


  public function executeSendmail()
    $mail = new myMail();
by Kota Sakoda on 2007-02-13, tagged email  encode  iso2022jp  japanese  sfmail  utf8 

Encode URL and caption like Smarty does ;)

This is very simple and effective mail helper. Original code is taken from Smarty's mailto plugin.
This helper scrambles your email addresses so those nasty web bots 'can not' harvest them.

In /lib/helper/MailEncodeHelper.php

function encode_mail($Address, $Caption=null)
  if ($Caption == null)
    $Caption = $Address;
  $string = 'document.write(\'<a href="mailto:'.$Address.'">'.$Caption.'</a>\');';
  $js_encode = '';
  for ($x=0; $x < strlen($string); $x++)
    $js_encode .= '%' . bin2hex($string[$x]);
  return '<script type="text/javascript">eval(unescape(\''.$js_encode.'\'))</script>';

In template

<?php use_helper('MailEncode') ?>
My email: <?php echo encode_mail(''); ?>  
My email: <?php echo encode_mail('', 'Damjan Malis'); ?>
by Damjan Malis on 2006-07-19, tagged email  encode  helper