PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Sep 15, 2019 3:38 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Apr 22, 2004 9:08 am 
Offline
Forum Newbie

Joined: Thu Apr 22, 2004 9:08 am
Posts: 2


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 9:12 am 
Offline
DevNet Resident
User avatar

Joined: Fri Aug 08, 2003 6:53 pm
Posts: 2101
Location: Sweden


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 9:59 am 
Offline
Forum Newbie

Joined: Thu Apr 22, 2004 9:08 am
Posts: 2
JAM,

thanks. i did try the search function and other forums as well. nowhere have i found the barebones code for this sort of thing. most codes are so complex it's impossible to dissect out the basics. i know this can't be as complicated as it seems . . .


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 11, 2004 5:12 am 
Offline
Forum Newbie
User avatar

Joined: Tue Jul 08, 2003 6:13 am
Posts: 16
Location: UK
Ok, hopefully this stuff all makes sense, bit basic but it should work, right first off on the page where your form is you want something like this
Syntax: [ Download ] [ Hide ]
<!--application form-->

                <script language="JavaScript">

                <!--

                // start validation



                function isEmail(elm)

                        {

                        if (elm.value.indexOf("@") + "" != "-1" &&

                                elm.value.indexOf(".") + "" != "-1" &&

                                elm.value != "")

                        return true;

                        else return false;

                        }



                function isFilled(elm) {

                        if (elm.value == "" ||

                                elm.value == null)

                        return false;

                        else return true;

                        }



                function isReady(form) {



                if (isEmail(form.EmailAddress) == false) {

                                alert("Please enter a correct email address.");

                                form.EmailAddress.focus();

                                return false;

                                }





                }

                // end validation

                //-->

                </script>



                <form method="post" action="email-attachment.php" enctype="multipart/form-data" onsubmit="return isReady(this)">

                <input type="hidden" name="MAX_FILE_SIZE" value="2048000">

                <table border="0" cellpadding="0" cellspacing="2">

                <tr>

                        <td align="left" class="text" valign="top">

                        Your email address:

                        </td>

                        <td align="left" valign="top">

                        <input type="text" name="EmailAddress" size="44" value="">

                        </td>

                </tr>

                <tr>

                        <td align="left" class="text" valign="top">

                        Please attach your file:

                        </td>

                        <td align="left" valign="top">

                        <input type="file" name="attachment" value="" size="24">

                        </td>

                </tr>

                        <td>&nbsp;</td>

                        <td><input type="submit" name="submit" value="send"></td>

                </table>


The javascript there just validates the email address.

On the page recieving the forms contents and send the email, you want something a bit like this.

Syntax: [ Download ] [ Hide ]
$message = stripslashes ("Some text");



        //add From: header

        $headers = "From: $EmailAddress\r\n";



        //specify MIME version 1.0

        $headers .= "MIME-Version: 1.0\r\n";



        //unique boundary

        $boundary = uniqid("HTMLDEMO");



        //tell e-mail client this e-mail contains//alternate versions

        $headers .= "Content-Type: multipart/mixed" .

                   "; boundary = $boundary\r\n\r\n";



        //message to people with clients who don't

        //understand MIME

        $headers .= "This is a MIME encoded message.\r\n\r\n";



        //plain text version of message

        $headers .= "--$boundary\r\n" .

           "Content-Type: text/plain; charset=ISO-8859-1\r\n" .

           "Content-Transfer-Encoding: base64\r\n\r\n";

        $headers .= chunk_split(base64_encode($message));



        // get attachment file details from the post

       

        $file_array = $_FILES[attachment];

        $file_type = $file_array[type];

        $filename = $file_array[tmp_name];



        // read file into a variable

       

        $fd = fopen ($filename, "r");

        $file = fread ($fd, filesize ($filename));

        fclose ($fd);



        $filename = $file_array[name];



        // encode file for the email

       

        $data = chunk_split(base64_encode($file));



        //File Attachment

       

        $headers .= "--{$boundary}\n" .  

                          "Content-Type: {$file_type};\n" .  

                          " name="{$filename}"\n" .  

                          "Content-Transfer-Encoding: base64\n\n" .  

                         $data . "\n\n" .  

                          "--{$boundary}--\n";  



        // send email

                         

        $success = mail("recipient@somenet.co.uk", "Email with attachment", "", $headers);


and that should send an email with an attachment, you'll need to play around with the $message variable and set it to your own text and of course update the recipient@somenet.co.uk to your email address, but that should do it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 11, 2004 5:14 am 
Offline
DevNet Master
User avatar

Joined: Thu Aug 15, 2002 5:53 am
Posts: 4235
Location: Sussex, UK
Alternatively, you can use the excellent .


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 11, 2004 5:17 am 
Offline
DevNet Resident

Joined: Tue Nov 18, 2003 2:09 pm
Posts: 1826
Location: Middlesbrough, UK
hehe, i remember reading this post ages ago,
no sweat guys, someone solved it


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group