Function encodeFileForEmail
Encode the contents of a file for emailing, including headers
$file can be an array, in which case it expects these members: 'filename' - the filename of the file 'contents' - the raw binary contents of the file as a string and can optionally include these members: 'mimetype' - the mimetype of the file (calculated from filename if missing) 'contentLocation' - the 'Content-Location' header value for the file
$file can also be a string, in which case it is assumed to be the filename
h5. contentLocation
Content Location is one of the two methods allowed for embedding images into an html email. It's also the simplest, and best supported
Assume we have an email with this in the body:
<img src="http://example.com/image.gif" />
To display the image, an email viewer would have to download the image from the web every time it is displayed. Due to privacy issues, most viewers will not display any images unless the user clicks 'Show images in this email'. Not optimal.
However, we can also include a copy of this image as an attached file in the email. By giving it a contentLocation of "http://example.com/image.gif" most email viewers will use this attached copy instead of downloading it. Better, most viewers will show it without a 'Show images in this email' conformation.
Here is an example of passing this information through Email.php:
$email = new Email(); $email->attachments[] = array( 'filename' =>
BASE_PATH . "/themes/mytheme/images/header.gif", 'contents' =>
file_get_contents(BASE_PATH . "/themes/mytheme/images/header.gif"), 'mimetype'
=> 'image/gif', 'contentLocation' => Director::absoluteBaseURL() .
"/themes/mytheme/images/header.gif" );
Parameters summary
mixed |
$file |
|
mixed |
$destFileName = false |
|
mixed |
$disposition = NULL |
|
mixed |
$extraHeaders = "" |