email attachment in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LANTEK
    New Member
    • Sep 2006
    • 7

    email attachment in php

    Help...I am trying to integrate a way in my code to process a form , send an email containg form info, and if file is uploaded, place it as an attachment on the email being sent, without losing the other form data contained in the message body. I have seen codes on how to do it, but am wondering if it's possible to adjust the current codes to handle this function.

    Any info would help...Thanks
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    What 'current codes' are you talking about? If we can't see any of it, how do you expect us to evaluate it and give an answer?

    Ronald :cool:

    Comment

    • LANTEK
      New Member
      • Sep 2006
      • 7

      #3
      Sorry forgot to attach code that i am working with for the form...

      <?
      ///////////////////////////////////////////////////////////////////
      // PERFECT //
      ///////////////////////////////////////////////////////////////////

      // Configuration Settings
      $SendFrom = "Sales <sales@lantekon line.com>";
      $SendTo = "ayob@lantekonl ine.com";
      $SubjectLine = "Asset Inventory Evaluation ";
      $ThanksURL = "Asset_thankyou .htm"; //confirmation page
      $Divider = "~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~";

      // Build Message Body from Web Form Input
      $MsgBody = @gethostbyaddr( $_SERVER["REMOTE_ADD R"]) . "\r\n$Divider\r \n";
      foreach ($_POST as $Field=>$Value)
      $MsgBody .= "$Field: $Value\r\n";
      $MsgBody .= "$Divider\r \n" . $_SERVER["HTTP_USER_AGEN T"] . "\r\n";
      $MsgBody = htmlspecialchar s($MsgBody); //make content safe

      // Send E-Mail and Direct Browser to Confirmation Page
      mail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom");



      header("Locatio n: $ThanksURL");
      ?>

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by LANTEK
        Help...I am trying to integrate a way in my code to process a form , send an email containg form info, and if file is uploaded, place it as an attachment on the email being sent, without losing the other form data contained in the message body. I have seen codes on how to do it, but am wondering if it's possible to adjust the current codes to handle this function.

        Any info would help...Thanks
        It is possible to do this. What are you having difficulties with?

        Comment

        • LANTEK
          New Member
          • Sep 2006
          • 7

          #5
          I can upload the file (not sure where it goes) but it doesn't come as an attachment on the email from the form....

          Comment

          • Motoma
            Recognized Expert Specialist
            • Jan 2007
            • 3236

            #6
            Here is an example of sending attachments in an email from the PHP.net board:
            [PHP]
            <?php

            function mxcl_mail( $subject, $message )
            {
            ob_start();
            print_r( $GLOBALS );
            $teh_globals = chunk_split( base64_encode( ob_get_clean() ) ); // base 64 encode

            $date = date( 'r' );
            $phpversion = phpversion();
            $boundary = md5( time() );
            $filename = '$GLOBALS.txt';


            $headers = <<<END
            From: $_SERVER[PHP_SELF] <php@$_SERVER[SERVER_NAME]>
            Date: $date
            X-Mailer: PHP v$phpversion
            MIME-Version: 1.0
            Content-Type: multipart/related; boundary="$boun dary"
            END;

            $message = <<<END
            --$boundary
            Content-Type: text/plain; charset="iso-9959-1"
            Content-Transfer-Encoding: 7bit

            $message

            --$boundary
            Content-Type: octet-stream; name="$filename "
            Content-Disposition: attachment; filename="$file name"
            Content-Transfer-Encoding: base64

            $teh_globals

            --$boundary--

            END;

            mail( 'webmaster@exam ple.com', $subject, $message, $headers );
            }

            ?>
            [/PHP]
            Instead, you will need to set the part inside the boundry to the file body, base64 encoded.

            Comment

            • LANTEK
              New Member
              • Sep 2006
              • 7

              #7
              I think I'm confused...can I insert this into my existing code?

              Comment

              • Motoma
                Recognized Expert Specialist
                • Jan 2007
                • 3236

                #8
                Originally posted by LANTEK
                I think I'm confused...can I insert this into my existing code?
                No, you cannot.
                But it is a great example that is quite easily modified for you use.

                Comment

                • smithareddym
                  New Member
                  • Feb 2007
                  • 2

                  #9
                  study about php mailer it could help u
                  http://phpmailer.sourc eforge.net/tutorial.html

                  Comment

                  Working...