Connecting Tech Pros Worldwide Help | Site Map

Need expert help with this HTML mail send process

marsandys@gmail.com
Guest
 
Posts: n/a
#1: Sep 30 '05
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 = "testmail@example.com";
$from_name = "POSTOFFICE";
$from_email = "postoffice@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>

Umberto Salsi
Guest
 
Posts: n/a
#2: Sep 30 '05

re: Need expert help with this HTML mail send process


marsandys@gmail.com wrote:
[color=blue]
> ...[/color]

- $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

George
Guest
 
Posts: n/a
#3: Sep 30 '05

re: Need expert help with this HTML mail send process


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

John Dunlop
Guest
 
Posts: n/a
#4: Sep 30 '05

re: Need expert help with this HTML mail send process


Umberto Salsi wrote:
[color=blue]
> - See RFC 2045-2049 for details about the MIME format.[/color]

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

--
Jock
Closed Thread


Similar PHP bytes