473,386 Members | 1,647 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,386 software developers and data experts.

Mail attachment questions...

Hi there,

I've found a script at these great Google fora. a script
to send emails with attachments.
The script is below this message, name etc. aren't mine, but from
the original post.

My questions are:
- Is this script extra heavy for a server, or should it be
no problem?
- How big do you advise for max size of attachments?
- Why is the attachment set in an array, when i remove the
array and only leave it's content-text i get a big time error.
- Why is this in there? --> $message .= str_replace ("=", "=3D",
$html_message)."\n";
- In the source of the mail, there are a few THOUSAND lines of
the following text. Right after "Content-ID: <image.jpg>"
"Do1QlNSe3k6QmpmR0hJTERWWlVhh4EQABAgQDAggIBwoKBwgC AwABAgMA"
what is it for? Does it delay my server?
I'm sorry if this seems kind of lazy from me, but i'm a newb so i
don't
know how to figure it out else.
Thanks in advance & Greetings
code from script below found at:
http://groups.google.nl/groups?hl=nl...ello.at&rnum=3
__________________________________________________ ____________
<?php
function sendmail ($from_name, $from_email, $to_name, $to_email,
$subject, $text_message="", $html_message="", $attachment="")
{
$from = "$from_name <$from_email>";
$to = "$to_name <$to_email>";
$main_boundary = "----=_NextPart_".md5(rand());
$text_boundary = "----=_NextPart_".md5(rand());
$html_boundary = "----=_NextPart_".md5(rand());
$headers = "From: $from\n";
$headers .= "Reply-To: $from\n";
$headers .= "X-Mailer: The Bat! (v2.04.7) Personal\n"; // say
we are
the bat mail client ;-)
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type:
multipart/mixed;\n\tboundary=\"$main_boundary\"\n";
$message = "\n--$main_boundary\n";
$message .= "Content-Type:
multipart/alternative;\n\tboundary=\"$text_boundary\"\n";
$message .= "\n--$text_boundary\n";
$message .= "Content-Type: text/plain;
charset=\"ISO-8859-1\"\n";
$message .= "Content-Transfer-Encoding: 7bit\n\n";
$message .= ($text_message!="")?"$text_message":"Text portion
of
HTML Email";
$message .= "\n--$text_boundary\n";
$message .= "Content-Type:
multipart/related;\n\tboundary=\"$html_boundary\"\n";
$message .= "\n--$html_boundary\n";
$message .= "Content-Type: text/html;
charset=\"ISO-8859-1\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n\n";
$message .= str_replace ("=", "=3D", $html_message)."\n";
if (isset ($attachment) && $attachment != "" && count
($attachment)
= 1)

{
for ($i=0; $i<count ($attachment); $i++)
{
$attfile = $attachment[$i];
$file_name = basename ($attfile);
$fp = fopen ($attfile, "r");
$fcontent = "";
while (!feof ($fp))
{
$fcontent .= fgets ($fp, 1024);
}
$fcontent = chunk_split (base64_encode($fcontent));
@fclose ($fp);
$message .= "\n--$html_boundary\n";
$message .= "Content-Type: application/octetstream\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-Disposition: inline;
filename=\"$file_name\"\n";
$message .= "Content-ID: <$file_name>\n\n";
$message .= $fcontent;
}
}
$message .= "\n--$html_boundary--\n";
$message .= "\n--$text_boundary--\n";
$message .= "\n--$main_boundary--\n";
@mail ($to, $subject, $message, $headers);
}
# Example
# Sender Name
$from_name = "ich bin ich";
# Sender Email
$from_email = "lu******@gmx.at";
# Recipient Name
$to_name = "Ludwig Moser";
# Recipient Email
$to_email = "lu******@gmx.at";
# Email Subject
$subject = "von mir an mich";
# Text Portion
$text_message = "This is HTML email and your email client softawre
ain't
support HTML email.";
# HTML Portion
$html_message = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0
Transitional//EN\">\n";
$html_message.= "<html><head><title></title>\n";
$html_message.= "<meta http-equiv=\"Content-Type\"
content=\"text/html;
charset=iso-8859-1\">\n";
$html_message.= "<style type=\"text/css\">\n";
$html_message.= "body, td {\nfont-family: Trebuchet
MS;\nfont-size:
12px;\n}\n";
$html_message.= "</style>\n";
$html_message.= "</head>\n";
$html_message.= "<body><table width=\"100%\" cellpadding=0
cellspacing=0><tr valign=top align=center>";
$html_message.= "<td width=300>This is my HTML Body\n<br>";
$html_message.= "<img src=\"cid:hh.jpg\"><br>\n";
$html_message.= "<font color=red>nice button heh?.";
$html_message.= "</td>";
$html_message.= "</tr></table>";
$html_message.= "</body></html>";

# Attachment Location
$attachment = array ("./go.gif"); // image in the same folder
# Execute SendMail Function
sendmail ($from_name, $from_email, $to_name, $to_email, $subject,
$text_message, $html_message, $attachment);
echo "mail sent.";
?>
Jul 17 '05 #1
2 3154
knoak wrote:
I've found a script at these great Google fora. a script
to send emails with attachments.
The script is below this message, name etc. aren't mine, but from
the original post.

My questions are:
- Is this script extra heavy for a server, or should it be
no problem?
I didn't study the script ... but it should be no problem unless (maybe)
you have a very large number of users using it.
- How big do you advise for max size of attachments?
0 bytes :-)
Really!

Automated mail from the php server should be small and plain.
In that mail let your users know the URL (by ftp of http) where they can
download a file.
- Why is the attachment set in an array, when i remove the
array and only leave it's content-text i get a big time error.
Maybe (I didn't look at the code) so that multiple attachs can be sent.
If you restructure some part of the code you have to know what that
implies to other parts and change them too.
- Why is this in there? --> $message .= str_replace ("=", "=3D",
$html_message)."\n";
That's for the encoding "quoted printable" stuff
http://en.wikipedia.org/wiki/Quoted-printable
- In the source of the mail, there are a few THOUSAND lines of
the following text. Right after "Content-ID: <image.jpg>"
"Do1QlNSe3k6QmpmR0hJTERWWlVhh4EQABAgQDAggIBwoKBwgC AwABAgMA"
what is it for? Does it delay my server?
That appears to be the separation between the different things sent
within the mail message.
http://www.faqs.org/rfcs/rfc2111.html

No, it does not delay your server (apart from the building of the
e-mail)

I'm sorry if this seems kind of lazy from me, but i'm a newb so i
don't know how to figure it out else.


Search the web and read, read, read :-)
Even if not all you find is accurate or up-to-date you will learn a lot
by reading and trying the things you find in your code.

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #2
knoak wrote:
Hi there,

I've found a script at these great Google fora. a script
to send emails with attachments. <snip> code from script below found at:

http://groups.google.nl/groups?hl=nl...ello.at&rnum=3

You may want to know <http://phpmailer.sourceforge.net/>

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: PeterR | last post by:
I've spent weeks trying to write a function that is simple to use for sending emails with attachments, but I my programming skills are not that advanced. I've noticed a few postings in these...
2
by: knoak | last post by:
Hi Pedro, I know i have to read a lot. :) But sometimes i need a little help from my friends, because i am the only one in my environment that experiments with php who could help me.. :( Few...
0
by: MAILER-DAEMON | last post by:
--------Message not delivered to the following addresses: shreeve@uci.edu --------Error Detail (phquery V3.0): ---- shreeve@uci.edu Does not exist, and no people with that name or...
0
by: imre.adam | last post by:
The original message was received at Wed, 2 Mar 2005 20:06:59 +0100 from 87.26.243.56 ----- The following addresses had permanent fatal errors ----- <python-list@python.org> ----- Transcript...
7
by: GeorgeAtkins | last post by:
I want to create a web-based form or page that consists of a series of formatted questions and answers. The form will resemble an existing paper form. When the form is filled in, I want the user to...
1
by: theWizard1 | last post by:
The following sends my email, but the attachment is empty. The attachment should contain the data that is in the string that was created from the xmlReader. I have a stored procedure written...
1
by: William Connery | last post by:
Hi, I have a small python program with e-mail capabilities that I have pieced together from code snippets found on the internet. The program uses the smtplib module to successfully send an...
2
by: eng.sharif | last post by:
hi group how i can send mail and attachement in php with "mail function " $s = mail($to,$subject,$cont, $headers); can anyone help
1
by: maxxxxel | last post by:
Hi Can anyone help me with some asp code , I changed the code to use CDO.message instead of the old cdont.sys to send mail from a ASP webpage which works fine. Our problem is that when we send...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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,...

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.