473,666 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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******@examp le.com";
$from_name = "POSTOFFICE ";
$from_email = "po********@exa mple.com";
$subject = "Incoming Test Message With Embedded Image";
$cc = $_POST['cc'];
$bcc = $_POST['bcc'];

$headers = "From: $from_name <$from_email>\n CC: $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=\"$fil e\"\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.j pg">--
Content-Type: image/jpeg; name="logo.jpg"
Content-Transfer-Encoding: base64
Content-ID: <logo.jpg>
Content-Disposition: inline; filename="logo. jpg"

/9j/4AAQSkZJRgABAgE ASABIAAD/4QjfRXhpZgAATU0 AKgAAAAgABwESAA MAAAABAAEAAAEaA AUA
AAABAAAAYgEbAAU AAAABAAAAagEoAA MAAAABAAIAAAExA AIAAAAUAAAAcgEy AAIAAAAUAAAAhod p
AAQAAAABAAAAnAA AAMgAAABIAAAAAQ AAAEgAAAABQWRvY mUgUGhvdG9zaG9w IDcuMAAyMDA1OjA 5
OjA1IDE0OjQzOjQ 2AAAAAAOgAQADAA AAAf//AACgAgAEAAAAAQA AAKGgAwAEAAAAAQ AAACIAAAAA
AAAABgEDAAMAAAA BAAYAAAEaAAUAAA ABAAABFgEbAAUAA AABAAABHgEoAAMA AAABAAIAAAIBAAQ A
AAABAAABJgICAAQ AAAABAAAHsQAAAA AAAABIAAAAAQAAA EgAAAAB/9j/4AAQSkZJRgABAgE ASABI
AAD/7QAMQWRvYmVfQ00 AAv/uAA5BZG9iZQBkgA AAAAH/2wCEAAwICAgJCAw JCQwRCwoLERUPDA wP
..........

<...the rest snipped for brevity>

Sep 30 '05 #1
3 2131
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=$bound ary\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
1891
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
9870
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 ********************************** package Celcom.Client;
5
3874
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: http://www.aestheticsurgerycenter.com/scripts/postcard/postcard1.shtml You can choose from some cards, add your own text and send it to a friend. This friend get a mail which tell him/her that he/she has a mail and have to click a link. So far everything works just fine. But when the recipient clicks...
5
4405
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 image) into the body of the email. Any help would be greatly appreciated. -- Nate Heaton
2
4526
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 from using system.web.mail to system.net.mail (of course vs is telling me system.web.mail is obsolete). In .Net 1.1, the files deleted with no problem but in .Net 2 when I attempt to delete I receive The process cannot access the file ...'...
16
2524
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 uses IE to talk with a server. The user on the client (IE) sees an ASP net page containing a TextBox. He can write some text in this text box and push a submit button.
0
3946
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 Inbox Reply from Craig Somerford <uscos@2barter.net> hide details 10:25 pm (3 minutes ago)
1
3203
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 code for attachment, I am not able to send anything. I get blank email. Can you please help me on this? Here is the html form:
5
2657
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 that even though the concurrent program runs, it should not send email on Saturdays and Sundays. The due date in the below code is always the next_day of the day I apply leave. It can be Saturday/Sunday. So my package is dependent on due date. ...
0
8454
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8362
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8878
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8785
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8560
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8644
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7389
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5671
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.