473,418 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 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 2118
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Jofio | last post by:
I am just learning PHP. I just tried coding a php script which I saved as mail.php ---------------------------- <? $name=$_POST; $email=$_POST; $comments=$_POST;
0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
5
by: Bernard | last post by:
Hi, I have a problem with a CGI script (Perl) on a Win2000 server. The script is for sending E-cards and was written by Jason Maloney:...
5
by: nate heaton | last post by:
I would like to do the following with C# in my asp.net app: Open the default email client of the user (just like a mailto: link would). Supply the subject line and put some HTML (including an...
2
by: Brad | last post by:
I have a web .Net app which sends emails with attachments. After the email is sent I clean up aftermyself and delete the attachments from disk. In upgrading to .Net 2 I changed the email logic...
16
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
1
by: deepaks85 | last post by:
Dear All, I want to send some data through a form with Multiple attachment in an HTML Format. I have tried it but it is not working for me. I am able to send data without attachment but with the...
5
by: vamsioracle | last post by:
Hi Folks I have written a code to send emails from oracle. Below is the code. I have registered this is Apps and scheduled the concurrent program to run every day. Now i want implement logic, such...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.