Sending a mail

Author Message

David Santiso

Saturday 28 May 2011 2:43:54 pm

Hi,

I've developed a new extension. In this extension I send a mail.The mail is sent correctly using my template, but the variables content doesn't display.

The code of my template is this:

{'Hi '} {$name}
{'...'}

When I receive mail only see this:

Hi

...

The part of my PHP code to construct and send the mail is this:

$Ini = eZINI::instance();
            
$emailSender = $Ini->variable( 'MailSettings', 'EmailSender' );

$mail = new eZMail();

$Tpl = eZTemplate::factory();

$templateResult = $Tpl->fetch( 'design:info_email.tpl' );

$Tpl->setVariable( 'name', 'David' );

$subject = 'TEST';
$mail->setSender( $emailSender );
$mail->setReceiver( 'mymail@mail.com' );
$mail->setSubject( $subject );
$mail->setBody( $templateResult );
$mail->setContentType( 'text/html' );

$mailResult = eZMailTransport::send( $mail );

Any idea?

Thanks,

David

Sao Tavi

Saturday 28 May 2011 3:23:55 pm

Maybe

$Tpl->setVariable( 'name', 'David' );

before

$templateResult = $Tpl->fetch( 'design:info_email.tpl' );

David Santiso

Saturday 28 May 2011 3:50:27 pm

I tried to display the template without sending mail and it displays the contents of variables, but when I send the mail, it doesn't display them.

Martin Weber

Friday 24 June 2011 8:28:04 am

Your first one can not work:

$mail = new eZMail();$Tpl = eZTemplate::factory();$templateResult = $Tpl->fetch( 'design:info_email.tpl' );$Tpl->setVariable( 'name', 'David' );$subject = 'TEST';$mail->setSender( $emailSender );$mail->setReceiver( 'mymail@mail.com' );$mail->setSubject( $subject );$mail->setBody( $templateResult );$mail->setContentType( 'text/html' );$mailResult = eZMailTransport::send( $mail );

You set the body with the $templateResult. This is returned by fetching the template but you set the variable after fetching.

Regards,
Martin

Jerome Despatis

Tuesday 28 June 2011 10:58:04 am

Important thing, eZMail is deprecated, gonna be replaced by ezcomponents (zetacomponents)  in the future. Not advised to use it

=> http://ezcomponents.org/docs/tutorials/Mail (you'll find there a working example)

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.