Code snippets for symfony 1.x

Navigation

Refine Tags

Snippets tagged "sfmail"

mail with symfony1.1 and swiftMailer

If you looking for an example to send an email from a tell-a-friend-form or other forms. this might help you:

function executeSend()
{
  [..] // your new sfForm-vodoo [..]
  // after posting form and validation
  $values = $this->form->getValues();
 
 // header
  $from = new Swift_Address( $values['email'], $values['firstname'] . ' ' . $values['lastname'] );
  $to   = new Swift_address( $values['rcpt_email'], $values['rcpt_name']);
  // subject/message
  $msg  = new Swift_Message( __( 'tellafriend.email.subject', '', 'tellafriend') ); // at this moment no body-text etc, we want multipart ...
 
  // content
  $placeholder = array();
  foreach ( $values as $key => $val ) {
    $placeholder['%'.$key.'%'] = $val;
  }
 
  // stuff, we need in the email
  sfContext::getInstance()->getRequest()->setAttribute( 'placeholder', $placeholder );
 
  // textversion
  $msg->attach(new Swift_Message_Part( sfContext::getInstance()->getController()->getPresentationFor( 'tellafriend', 'sendEmailText', $viewName = null) ));
  // htmlversion
  $msg->attach(new Swift_Message_Part( sfContext::getInstance()->getController()->getPresentationFor( 'tellafriend', 'sendEmailHTML', $viewName = null), "text/html") );
 
  $stream = $msg->build();
  //echo $stream->readFull(); die; //Dumps the email contents
 
  // and send
  $swift = new Swift(new Swift_Connection_NativeMail());
  $swift->send( $msg, $to, $from );
  $swift->disconnect();
 
}
 
function executeSendEmailText()
{
  // holds your text-version-template
  $this->placeholder = $this->getRequest()->getAttribute('placeholder');
}
 
function executeSendHTMLText()
{
  // holds your html-version-template
  $this->placeholder = $this->getRequest()->getAttribute('placeholder');
}
 

full documentation for swiftMailer you find here: http://www.swiftmailer.org/wikidocs/

by Susan Lau on 2008-04-15, tagged sfmail  swift  symfony11 
(2 comments)

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

myMail.class.php

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

actions.class.php

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