How to send an email with attachments with eZmail ?

Author Message

Aldo Medri

Wednesday 28 April 2010 9:15:04 am

Hello all,
I've tried unsuccessfully to send an e-mail with attachments using eZmail, here is the code:

$arrAttach['filename'] = "name_of_first_file.txt";
$arrAttach['content'] = "file content";
$arrAttachments[] = $arrAttach;

function my_send_email_attach($fromName, $fromEmail, $toName, $toEmail, $htmlMsg, $oggetto, $messaggio, $arrAttachments) {
    $uid = md5(uniqid(time()));
    $header = "From: ".$fromName." <".$fromEmail.">\r\n";
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";

    $ez_headers = array();
    $ez_headers['From'] = "".$fromName." <".$fromEmail.">";

    $ez_extra_headers = "";
    $ez_extra_headers .= "MIME-Version: 1.0\r\n";
    $ez_extra_headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"";

    // $body = "This is a multi-part message in MIME format.\r\n";
    $body = "--".$uid."\r\n";
    $body .= "Content-type:text/plain; charset=iso-8859-1\r\n";
    $body .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $body .= $messaggio."\r\n\r\n";
    foreach ($arrAttachments as $arrAttach)
    {
        $filename = $arrAttach['filename'];
        $content = $arrAttach['content'];
        $content = chunk_split(base64_encode($content));
        $body .= "--".$uid."\r\n";
        $body .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
        $body .= "Content-Transfer-Encoding: base64\r\n";
        $body .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
        $body .= $content."\r\n\r\n";
    }
    $body .= "--".$uid."--";

    include_once('lib/ezutils/classes/ezmail.php');
    include_once('lib/ezutils/classes/ezmailtransport.php');

    $mail = new eZMail();
    if (""!=$htmlMsg)
    {
        $mail->setContentType('text/html');
    }
    $mail->setReceiver( $toEmail, $toName );
    $mail->setSender( $fromEmail, $fromName );
    $mail->setSubject( $oggetto );
    $mail->setBody( $body );
    // $mail->headers( $ez_headers );
    $mail->setExtraHeaders( $ez_extra_headers );
    $mailResult = eZMailTransport::send( $mail );
    return $mailResult;
}

why doesn't it work correctly?
thank you in advance...

Massimiliano Collavo

Tuesday 18 May 2010 7:48:58 am

Hello Aldo,

You can use ezcomponents , http://ezcomponents.org/docs/tutorials/Mail

works well.

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 03:06:24
Script start
Timing: Jan 18 2025 03:06:24
Module start 'layout'
Timing: Jan 18 2025 03:06:24
Module start 'content'
Timing: Jan 18 2025 03:06:24
Module end 'content'
Timing: Jan 18 2025 03:06:24
Script end

Main resources:

Total runtime0.7596 sec
Peak memory usage4,096.0000 KB
Database Queries54

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0060 588.0469152.6406
Module start 'layout' 0.00600.0025 740.687539.4922
Module start 'content' 0.00850.7497 780.1797498.3203
Module end 'content' 0.75810.0014 1,278.500012.1250
Script end 0.7595  1,290.6250 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.4061160.0002
Check MTime0.00130.1700160.0001
Mysql Total
Database connection0.00080.102010.0008
Mysqli_queries0.720094.7864540.0133
Looping result0.00040.0535520.0000
Template Total0.734496.720.3672
Template load0.00200.259620.0010
Template processing0.732496.422820.3662
Template load and register function0.00010.013210.0001
states
state_id_array0.00080.099310.0008
state_identifier_array0.00090.117720.0004
Override
Cache load0.00160.2054130.0001
Sytem overhead
Fetch class attribute can translate value0.00060.077720.0003
Fetch class attribute name0.00120.155130.0004
XML
Image XML parsing0.00140.188520.0007
class_abstraction
Instantiating content class attribute0.00000.001030.0000
General
dbfile0.00160.2160150.0001
String conversion0.00000.001340.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
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
3content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 11
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs