Can someone please post a code snippet for attaching a file to an email?
Announcement
Collapse
No announcement yet.
Sendemail() or MvSMTP attachment
Collapse
X
-
Re: Sendemail() or MvSMTP attachment
Code:<MvSMTP TO="{g.EmailTo}" SUBJECT="{ $Stores.d.name$ ' Containing: ' $g.Common_Batch_Name }" MAILHOST="{domain.d.mailhost}" FROM="{Stores.d.email}"> <MvEVAL EXPR="{'MIME-Version: 1.0' $ l.cr}"> <MvEVAL EXPR="{'Content-Type: application/octet-stream; name="' $g.Name$g.File$'"' $ l.cr}"> <MvEVAL EXPR="{'Content-Transfer-Encoding: 8bit' $ l.cr}"> <MvEVAL EXPR="{'Content-Disposition: attachment; filename="' $g.Name$g.File$'"' $ l.cr $ l.cr}"> <MvEVAL EXPR="{g.Data}"> </MvSMTP>
Bruce Golub
Phosphor Media - "Your Success is our Business"
Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
phosphormedia.com
-
Re: Sendemail() or MvSMTP attachment
i believe that's originally from Ivo...Bruce Golub
Phosphor Media - "Your Success is our Business"
Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
phosphormedia.com
Comment
-
Re: Sendemail() or MvSMTP attachment
Hi,
Edit: As you already have the code for attaching documents (Bruce is fast! :P), I thought it could be interesting to share the following code for those who don't know how to integrate images in the body of the e-mail***
Here is a piece of code that I used (I extracted it from one of my modules and didn't tested so you should take it just an example, but it should work :))
This code will include images in the body of the e-mail, so your user will not see broken images (with the famous "activate images" link in Outlokk) and it should pass anti-spam basic filters ( of course, I'm NOT saying that you should use that code to spam, I'm saying it's very annoing when my opt-in clients don't receive some newsletter because of the anti-spam filters)
Other thing, it uses alternative content (text and html). This way you are closer to the standards and you give the possibility to those who deactivated theirs HTML viewing to see the content of the e-mail.
You will see in the code that you have to use full web path for your images (ex: http://domain.com/img.jpg). This way, mail systems that don't allow 64 encoded data in the body of the e-mail, will show the web images. (like old Horde or Squirrelmail)
By the way, I used charset="iso-8859-1" (I'm in France, it's no secret :D) ... so you should change that to utf-8 :P
PHP Code:
<MvCOMMENT>
Here we suppose that you have encoded the images and you have the following variables:
- l.encoded64file[l.counter] : The base 64 data (you can use crypto_base64_encode( data ) but beware of the empty line at the end.
- l.pathfile[l.counter] : wich is better to use with full 'http' path: ex: http://mydomain.com/image.jpg
</MvCOMMENT>
<MvWHILE EXPR="{ l.cnt LT l.no_images }">
<mvassign name="l.cnt" value="{l.cnt+1}">
<mvassign name="l.boundary" value="{l.boundary$'------=_NextPart_000_020D_01C3FB44.3DF09230' $ l.cr
$'Content-Type: application/octet-stream;' $ l.cr
$'Content-Transfer-Encoding: base64 ' $ l.cr
$'Content-Location: '$l.pathfile[l.cnt]$ l.cr $ l.cr
$ l.encoded64file[l.cnt] $ l.cr$ l.cr}">
</MvWHILE>
<MvASSIGN NAME="l.cr" VALUE="{asciichar(13) $ asciichar(10)}">
<MvSMTP FROM="{l.expediteur}" TO = "{l.destinataire}"
SUBJECT = "{l.sujet}"
CC = "{l.cec}"
MAILHOST = "{l.smtp}">
<MvEVAL EXPR="{'MIME-Version: 1.0' $ l.cr
$'Content-Type: multipart/related;' $ l.cr
$' type="multipart/alternative";' $ l.cr
$' boundary="----=_NextPart_000_020D_01C3FB44.3DF09230"' $ l.cr
$'X-Priority: 3' $ l.cr
$'X-MSMail-Priority: Normal' $ l.cr
$'X-Mailer: Your mailsolution name ' $ l.cr
$'X-MimeOLE: Produced By Your Name - www.yourdomain.com' $ l.cr $ l.cr
$'This is a multi-part message in MIME format.' $ l.cr$ l.cr
$'------=_NextPart_000_020D_01C3FB44.3DF09230' $ l.cr
$'Content-Type: multipart/alternative;' $ l.cr
$' boundary="----=_NextPart_001_0157_01C4B28A.B41B8570"' $ l.cr$ l.cr$ l.cr
$'------=_NextPart_001_0157_01C4B28A.B41B8570' $ l.cr
$'Content-Type: text/plain;' $ l.cr
$' charset="iso-8859-1"' $ l.cr
$'Content-Transfer-Encoding: 8bit' $ l.cr$ l.cr
$ l.text_format_message $l.cr$l.cr
$'------=_NextPart_001_0157_01C4B28A.B41B8570' $ l.cr
$'Content-Type: text/html;' $ l.cr
$' charset="iso-8859-1"' $ l.cr
$'Content-Transfer-Encoding: 8bit' $ l.cr
$'Content-Location: http://'$s.http_host$'/'$ l.cr$ l.cr
$'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'$ l.cr
$'<HTML><HEAD><TITLE>Emailing title</TITLE>'$ l.cr
$'<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">'$ l.cr
$'<META content="MSHTML 6.00.2800.1170" name=GENERATOR></HEAD>'$ l.cr
$'<BODY text=#000000 vLink=#0000 aLink=#0000 link=#0000 bgColor=#ffffff>'$ l.cr
$l.html_message
$'</BODY></HTML>'$ l.cr$ l.cr
$'------=_NextPart_001_0157_01C4B28A.B41B8570--'$ l.cr $ l.cr
$l.boundary$'------=_NextPart_000_020D_01C3FB44.3DF09230--'}">
</MvSmtp>
How not to abuse Mime http://forum.spamcop.net/forums/lofi...php/t9024.html
Ivo's page: http://mivo.truxoft.com/art0040.htm (I know everyone knows it :D I just want to give credits !)
And all the footer refs on the Ivo's page:
MimeConv 2.0
RFC-2045: MIME - Format of Internet Message Bodies
RFC-2046: MIME - Media Types
RFC-2047: MIME - Message Header Extensions for Non-ASCII Text
RFC-2048: MIME - Registration Procedures
RFC-2049: MIME - Conformance Criteria and Examples
RFC-821: SMTP - Simple Mail Transfer Protocol
RFC-1652: SMTP Service Extension for 8bit-MIMEtransport
RFC Editor
Search the RFC Database
Comment
Comment