Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Send HTML message + attachment

7:51 pm on Jun 13, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 30, 2008
votes: 0

I'm building a WordPress plugin that requires an email to be sent with an attachment and HTML message. I've found a post online, but it doesn't seem to be working.

Here are the long headers output by Mail.app:

Content-Type: application/pdf; name="summary.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="summary.pdf"

Content-Type: multipart/alternative
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

1:48 pm on June 15, 2010 (gmt 0)


WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
votes: 2

Here is an example that has been stripped from a class where I add attachments to an array with the key being the file name and the value is the actual file contents (pdf document, picture, etc.)
if ($this->_attachments) { 
$boundary = '=_' . md5(rand() . microtime());
$headers['MIME-Version'] = '1.0';
$headers['Content-Type'] = "multipart/mixed;{$this->CRLF}\tboundary=\"{$boundary}\"";
$hdrs = "--{$boundary}{$this->CRLF}";
$hdrs .= "Content-Transfer-Encoding: 7bit{$this->CRLF}";
$hdrs .= "Content-Type: text/plain; charset=\"ISO-8859-1\"{$this->CRLF}";
$this->message = $hdrs . $this->CRLF . $this->message;
foreach ($this->_attachments as $filename => $file) {
$hdrs = "--{$boundary}{$this->CRLF}";
$hdrs .= "Content-Transfer-Encoding: base64{$this->CRLF}";
$hdrs .= "Content-Type: application/octet-stream;{$this->CRLF}\tname=\"{$filename}\"{$this->CRLF}";
$hdrs .= "Content-Disposition: attachment;{$this->CRLF}\tfilename=\"{$filename}\"{$this->CRLF}";
$this->message .= $hdrs . $this->CRLF . rtrim(chunk_split(base64_encode($file), 76, $this->CRLF)) . $this->CRLF;
$this->message .= "--{$boundary}--{$this->CRLF}";

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members