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.

eZ debug

Timing: Jan 18 2025 02:44:43
Script start
Timing: Jan 18 2025 02:44:43
Module start 'layout'
Timing: Jan 18 2025 02:44:43
Module start 'content'
Timing: Jan 18 2025 02:44:44
Module end 'content'
Timing: Jan 18 2025 02:44:44
Script end

Main resources:

Total runtime0.7961 sec
Peak memory usage4,096.0000 KB
Database Queries68

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0099 587.7891152.6094
Module start 'layout' 0.01000.0053 740.398439.4141
Module start 'content' 0.01530.7791 779.8125569.6094
Module end 'content' 0.79440.0017 1,349.421912.2031
Script end 0.7961  1,361.6250 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00410.5187160.0003
Check MTime0.00160.1983160.0001
Mysql Total
Database connection0.00170.215710.0017
Mysqli_queries0.729291.5918680.0107
Looping result0.00100.1214660.0000
Template Total0.755294.920.3776
Template load0.00220.277120.0011
Template processing0.753094.584820.3765
Template load and register function0.00020.024310.0002
states
state_id_array0.00150.183810.0015
state_identifier_array0.00130.162020.0006
Override
Cache load0.00190.2375360.0001
Sytem overhead
Fetch class attribute can translate value0.00120.154240.0003
Fetch class attribute name0.00180.223650.0004
XML
Image XML parsing0.00070.082040.0002
class_abstraction
Instantiating content class attribute0.00000.002250.0000
General
dbfile0.00090.1129100.0001
String conversion0.00000.001940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
13content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/emphasize.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/emphasize.tplEdit templateOverride template
2content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 31
 Number of unique templates used: 9

Time used to render debug report: 0.0001 secs