By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,044 Members | 1,291 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,044 IT Pros & Developers. It's quick & easy.

Mail attachment questions...

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.