472,101 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,101 software developers and data experts.

Need expert help with this HTML mail send process

Hello, I have this code below, which I am trying to have it send HTML
formatted mail with embedded images. I can get this to send the mail,
but it spits out a bunch of junk [output of this is below]. I know
this should be pretty simple, but I have been pulling my hair out for
hours with this. :/ Can someone smart pleaseeee help me tweak this
code to work?

<?php
// Read POST request params into global vars

$to = "te******@example.com";
$from_name = "POSTOFFICE";
$from_email = "po********@example.com";
$subject = "Incoming Test Message With Embedded Image";
$cc = $_POST['cc'];
$bcc = $_POST['bcc'];

$headers = "From: $from_name <$from_email>\nCC: $cc\nBCC: $bcc\n";

$html_body =
"This is a multi-part message in MIME format.\n"
. "--$boundary\n"
. "Content-Type: text/html; charset=\"iso-8859-1\"\n"
. "Content-Transfer-Encoding:8bit\n"
. "\n"
. "This is some text I wanted printed plus this embedded
image <img src=\"cid:logo.jpg\">";

$file = "logo.jpg";
$path = "/home/images/logo.jpg";
$fp = fopen( $path,"r" );
$attachment = fread( $fp,filesize( $path ) );
$attachment = chunk_split( base64_encode( $attachment ) );
fclose( $fp );
$html_body .= "--$boundary\n"
. "Content-Type: image/jpeg; name=\"$file\"\n"
. "Content-Transfer-Encoding: base64\n"
. "Content-ID: <$file>\n"
. "Content-Disposition: inline; filename=\"$file\"\n"
. "\n"
. $attachment . "\n"
. "\n\n";

// Send the message
$ok = @mail($to, $subject, $html_body, $headers);
if ($ok) {
echo "<p>Message(s) sent.</p>";
} else {
echo "<p>NOTE: Message(s) could not be sent.</p>";
}
?>

OUTPUTS:

This is a multi-part message in MIME format.
--
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding:8bit

This is some text I wanted printed plus this embedded image <img
src="cid:logo.jpg">--
Content-Type: image/jpeg; name="logo.jpg"
Content-Transfer-Encoding: base64
Content-ID: <logo.jpg>
Content-Disposition: inline; filename="logo.jpg"

/9j/4AAQSkZJRgABAgEASABIAAD/4QjfRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUA
AAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAA AUAAAAcgEyAAIAAAAUAAAAhodp
AAQAAAABAAAAnAAAAMgAAABIAAAAAQAAAEgAAAABQWRvYmUgUG hvdG9zaG9wIDcuMAAyMDA1OjA5
OjA1IDE0OjQzOjQ2AAAAAAOgAQADAAAAAf//AACgAgAEAAAAAQAAAKGgAwAEAAAAAQAAACIAAAAA
AAAABgEDAAMAAAABAAYAAAEaAAUAAAABAAABFgEbAAUAAAABAA ABHgEoAAMAAAABAAIAAAIBAAQA
AAABAAABJgICAAQAAAABAAAHsQAAAAAAAABIAAAAAQAAAEgAAA AB/9j/4AAQSkZJRgABAgEASABI
AAD/7QAMQWRvYmVfQ00AAv/uAA5BZG9iZQBkgAAAAAH/2wCEAAwICAgJCAwJCQwRCwoLERUPDAwP
..........

<...the rest snipped for brevity>

Sep 30 '05 #1
3 2031
ma*******@gmail.com wrote:
...


- $boundary has not been assigned. For example: $boundary = "1234567890";

- These lines are required in the email header:

$headers .=
"MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=$boundary\n";

- See RFC 2045-2049 for details about the MIME format.

Regards,
___
/_|_\ Umberto Salsi
\/_\/ www.icosaedro.it

Sep 30 '05 #2
One of the things I've found recently, mainly because I wanted to send
several messages with HTML and text versions was that PEAR was a pretty
good avenue, however it doesn't seem to work with q-mail. I went to
the HTML Mime mail from phpguru.org and started using that. It's a
simple interface, and easy to create the messages with it.
http://www.phpguru.org/static/mime.mail.html

Just a thought.
George
www.fairmontstudios.com

Sep 30 '05 #3
Umberto Salsi wrote:
- See RFC 2045-2049 for details about the MIME format.


And note particularly that line breaks are denoted by CRLF pairs, and that
lone CRs or LFs are not allowed in 8bit data.

--
Jock
Sep 30 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Jofio | last post: by
reply views Thread by James Hong | last post: by
5 posts views Thread by Bernard | last post: by
5 posts views Thread by nate heaton | last post: by
reply views Thread by U S Contractors Offering Service A Non-profit | last post: by
5 posts views Thread by vamsioracle | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.