Mail attachment questions...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • knoak

    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>"
    "Do1QlNSe3k6Qmp mR0hJTERWWlVhh4 EQABAgQDAggIBwo KBwgCAwABAgMA"
    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:

    _______________ _______________ _______________ _______________ __
    <?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_".md 5(rand());
    $text_boundary = "----=_NextPart_".md 5(rand());
    $html_boundary = "----=_NextPart_".md 5(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\tbound ary=\"$main_bou ndary\"\n";
    $message = "\n--$main_boundary\ n";
    $message .= "Content-Type:
    multipart/alternative;\n\ tboundary=\"$te xt_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_mes sage":"Text portion
    of
    HTML Email";
    $message .= "\n--$text_boundary\ n";
    $message .= "Content-Type:
    multipart/related;\n\tbou ndary=\"$html_b oundary\"\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)[color=blue]
    >= 1)[/color]
    {
    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=\"$fil e_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 = "luke2000@gmx.a t";
    # Recipient Name
    $to_name = "Ludwig Moser";
    # Recipient Email
    $to_email = "luke2000@gmx.a t";
    # 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><t itle></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><tab le 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.jp g\"><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.";
    ?>
  • Pedro Graca

    #2
    Re: Mail attachment questions...

    knoak wrote:[color=blue]
    > 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?[/color]

    I didn't study the script ... but it should be no problem unless (maybe)
    you have a very large number of users using it.
    [color=blue]
    > - How big do you advise for max size of attachments?[/color]

    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.
    [color=blue]
    > - 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.[/color]

    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.
    [color=blue]
    > - Why is this in there? --> $message .= str_replace ("=", "=3D",
    > $html_message). "\n";[/color]

    That's for the encoding "quoted printable" stuff

    [color=blue]
    > - In the source of the mail, there are a few THOUSAND lines of
    > the following text. Right after "Content-ID: <image.jpg>"
    > "Do1QlNSe3k6Qmp mR0hJTERWWlVhh4 EQABAgQDAggIBwo KBwgCAwABAgMA"
    > what is it for? Does it delay my server?[/color]

    That appears to be the separation between the different things sent
    within the mail message.


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

    [color=blue]
    > 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.[/color]

    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!

    Comment

    • R. Rajesh Jeba Anbiah

      #3
      Re: Mail attachment questions...

      knoak wrote:[color=blue]
      > Hi there,
      >
      > I've found a script at these great Google fora. a script
      > to send emails with attachments.[/color]
      <snip>[color=blue]
      > code from script below found at:
      >[/color]


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

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

      Comment

      Working...