Forum FAQForum FAQSearchSearch MemberlistMemberlist Forum ignore listForum ignore list RegisterRegister ProfileProfile Log in to check your private messagesLog in to check your private messages Log inLog in
contact form + upload

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Server-side
View previous topic :: View next topic  
Author Message
n0p



Joined: 21 Apr 2006
Posts: 39
Location: wWw

PostPosted: 10.08.2009 08:16    Post subject: contact form + upload Add user to your forum ignore list Reply with quote

Zanima me jel tko od vas trebao ovaku kontakt forumu dakle standardna polja + upload fajla koji se tako?er ?alje na e-mail...tra?io sam malo po netu za gotove ali nisam ni?ta konkretno na?ao....pa ako tko ima kakvi link bio bi mu zahvalan
________
Suzuki GSX-R Series history

Last edited by n0p on 02.02.2011 11:40; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
zytzagoo
mi3.crew


Joined: 25 Aug 2003
Posts: 1842
Location: Zagreb, Hrvatska

PostPosted: 11.08.2009 14:26    Post subject: Add user to your forum ignore list Reply with quote

Nije komplicirano, trebas samo ispravno headere posloziti. Evo ti source fiktivnog formulara
slozenog nabrzaka, s podrskom za neograniceni broj attachmenta i ostalo:

http://zytzagoo.net/mi3.tests/n0p/contact-form-with-attachment.phps

_________________
[+]I[+]am[+]my[+]own[+]religion[+]
Back to top
View user's profile Send private message Visit poster's website Twitter profile
n0p



Joined: 21 Apr 2006
Posts: 39
Location: wWw

PostPosted: 04.09.2009 15:12    Post subject: Add user to your forum ignore list Reply with quote

slo?io sma to u jedan gotovi contact form ali ne radi...de dolazi attechment
Code:

            <!-- The contact form starts from here-->
            <?php

            $valid_mime_types = array(
               'application/x-msword-doc',
               'application/x-zip-compressed',
               'application/force-download',
               'application/download',
               'application/doc',
               'application/octet-stream',
               'application/rtf',
               'application/richtext',
               'application/pdf',
               'application/x-pdf',
               'application/msword',
               'application/vnd.wordperfect',
               'application/vnd.ms-excel',
               'application/applefile',
               'application/x-msword',
               'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
               'application/vnd.oasis.opendocument.text',
               'text/plain',
               'text/html',
               'text/rtf',
               'text/richtext',
               'application/zip',
               'application/unknown'
            );

            $upload_filesize_limit = 1048576; // bytes

            $email_charset = 'utf-8';
            $email_content_type = 'text/plain';

            // the email will be sent here
            // make sure to change this to be your e-mail
            $email_to      = "info@domena.com";

            $ok = false;

            $error    = ''; // error message
                $name     = ''; // sender's name
                $email_from    = ''; // sender's email address
                $email_subject  = ''; // subject
            $mail_msg   = ''; // mail message
                  $spamcheck = ''; // Spam check
            $headers = ''; // Headers


            if(isset($_POST['send']))
            {
         
            // the "fixed" part of the message, if there is any...
            $mail_msg = "\nPozdrav,\n\nSljede?a poruka je poslana koriste?i formu na Va?im stranicama.\n";
            $mail_msg .= "Datoteke poslane preko forme bi se trebale nalaziti u privitku.\n\n";

            $name     = $_POST['name'];
                $email_from    = $_POST['email'];
                $subject  = $_POST['subject'];
                $mail_msg  .= $_POST['message'];
                  $spamcheck = $_POST['spamcheck'];

                if(trim($name) == '')
                {
                    $error = '<div class="errormsg">Please enter your name!</div>';
                }
                   else if(trim($email_from) == '')
                {
                    $error = '<div class="errormsg">Please enter your email address!</div>';
                }
                else if(!isEmail($email_from))
                {
                    $error = '<div class="errormsg">You have enter an invalid e-mail address. Please, try again!</div>';
                }
                   if(trim($subject) == '')
                {
                    $error = '<div class="errormsg">Please enter a subject!</div>';
                }
               else if(trim($mail_msg) == '')
                {
                    $error = '<div class="errormsg">Please enter your message!</div>';
                }
                else if(trim($spamcheck) == '')
               {
                  $error = '<div class="errormsg">Please enter the number for Spam Check!</div>';
               }
                else if(trim($spamcheck) != '5')
               {
                  $error = '<div class="errormsg">Spam Check: The number you entered is not correct! 2 + 3 = ???</div>';
               }
                if($error == '')
                {
                    if(get_magic_quotes_gpc())
                    {
                        $mail_msg = stripslashes($mail_msg);
                    }


                    // the email subject
                    // '[Contact Form] :' will appear automatically in the subject.
                    // You can change it as you want

                    $email_subject = '[Contact Form] : ' . $subject;

               $filecount = 0;
               $data = null;

               if (isset($_FILES) && !empty($_FILES)) {

                  // this should work for any number of uploaded files, each will be attached separately
                  foreach ($_FILES as $file => $value) {
                     $attachment[(int)$filecount] = $_FILES[$file]['tmp_name'];
                     $attachment_name[(int)$filecount] = $_FILES[$file]['name'];
                     if (is_uploaded_file($attachment[(int)$filecount])) {
                        if ($_FILES[$file]['size'] <= $upload_filesize_limit) {
                           // does the file comply with our allowed mime types?
                           if (in_array($_FILES[$file]['type'], $valid_mime_types)) {
                              $fp = fopen($attachment[(int)$filecount], "rb");
                              $data[(int)$filecount] = fread($fp, filesize($attachment[(int)$filecount]));
                              // chunk it up and base64 encode so it can be emailed
                              $data[(int)$filecount] = chunk_split(base64_encode($data[(int)$filecount]));
                              fclose($fp);
                              $filecount++;
                           }
                        }
                     }
                  }
               }

               // build e-mail headers

               $headers = "MIME-Version: 1.0\n";
               $headers .= "From: " . $email_from . "\n";
               $headers .= "Reply-To: " . $email_to . "\n";
               $headers .= "Content-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"----=MIME_BOUNDRY_main_message\"\n";
               $headers .= "X-Sender: " . $email_from . "\n";
               $headers .= "X-Mailer: PHP\n";

               $headers .= "X-Priority: 3\n";// 1 = Urgent, 3 = Normal
               $headers .= "Return-Path: " . $email_from . "\n";
               $headers .= "This is a multi-part message in MIME format.\n";
               $headers .= "------=MIME_BOUNDRY_main_message\n";
               $headers .= "Content-Type: multipart/alternative; boundary=\"----=MIME_BOUNDRY_message_parts\"\n";
               $message  = "------=MIME_BOUNDRY_message_parts\n";
               $message .= "Content-Type: " . $email_content_type . "; charset=\"" . $email_charset . "\"\n";
               $message .= "Content-Transfer-Encoding: quoted-printable\n";
               $message .= "\n";
               // add our message (in this case it's plain text, could be html as well)
               $message .= $mail_msg . "\n";
               $message .= "\n";
               $message .= "------=MIME_BOUNDRY_message_parts--\n";
               $message .= "\n";

               for ($i = 0, $filecount = (int) count($data); $i < $filecount; $i++) {
                  $message .= "------=MIME_BOUNDRY_main_message\n";
                  $message .= "Content-Type: application/octet-stream;\n\tname=\"" . $attachment_name[$i] . "\"\n";
                  $message .= "Content-Transfer-Encoding: base64\n";
                  $message .= "Content-Disposition: attachment;\n\tfilename=\"" . $attachment_name[$i] . "\"\n\n";
                  $message .= $data[$i]; //The base64 encoded message
                  $message .= "\n\n";
               }

               $message .= "------=MIME_BOUNDRY_main_message--\n";

               // die($email_subject . "<br>" . $message);

               // send the message
               $ok = mail($email_to, $email_subject, $message, $headers);
               if ($ok) {
                  $success_message = 'Va?a poruka je uspje?no poslana!';
               }
            }

            if($ok)
            print '
                  <!-- Message sent! (change the text below as you wish)-->
                  <div style="text-align:center;">
                    <h1>Congratulations!!</h1>
                       <p><?=$success_message?></p>
                  </div>
                  <!--End Message Sent-->
             ';
         }

            if(!isset($_POST['send']) || $error != '')
            {
            ?>

            <h1>Contact Form Example:</h1>
            <!--Error Message-->
            <?=$error;?>

            <form  method="post" name="contFrm" id="contFrm" action="">


                      <label><span class="required">*</span> Full Name:</label>
                     <input name="name" type="text" class="box" id="name" size="30" value="<?=$name;?>" />

                     <label><span class="required">*</span> Email: </label>
                     <input name="email" type="text" class="box" id="email" size="30" value="<?=$email_from;?>" />

                     <label><span class="required">*</span> Subject: </label>
                     <input name="subject" type="text" class="box" id="subject" size="30" value="<?=$email_subject;?>" />

                       <label><span class="required">*</span> Message: </label>
                       <textarea name="message" cols="40" rows="3"  id="message"><?=$mail_msg;?></textarea>

                  <!--input type="hidden" name="max_file_size" value="<?php echo $upload_filesize_limit; ?>"-->
                  <label for="f_cv">Datoteka 1</label>
                  <input name="attachment_cv" id="f_cv" size="20" type="file">
                  <p class="form_info">Dopu?tene datoteke: <strong>.doc, .pdf, .rtf, .txt</strong><br>Max. file size: <strong>1MB</strong></p>

                  <label for="f_letter">Datoteka 2</label>
                  <input name="attachment_letter" id="f_letter" size="20" type="file">
                  <p class="form_info">Dopu?tene datoteke: <strong>.doc, .pdf, .rtf, .txt</strong><br>Max. file size: <strong>1MB</strong></p>

                     <label><span class="required">*</span> Spam Check: <b>2 + 3=</b></label>
                  <input name="spamcheck" type="text" class="box" id="spamcheck" size="4" value="<?=$spamcheck;?>" />

                     <!-- Submit Button-->
                       <input name="send" type="submit" class="button" id="send" value="" />

            </form>

            <!-- E-mail verification. Do not edit -->
            <?php
            }

            function isEmail($email)
            {
                return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|b
h|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu
|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|
gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|k
i|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms
|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|
pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|
sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|
vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-
9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i"
                        ,$email));
            }
            ?>
            <!-- END CONTACT FORM -->

            <p>&nbsp;</p>
            <p style="text-align:center;">Go to the <a href="http://web-kreation.com/index.php/freebies/" title="Download the Contact form">Freebies</a> page to download this contact form.</p>
     
     </div> <!-- /contentForm -->

________
VOLCANO VAPORIZERS

Last edited by n0p on 20.03.2011 07:03; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
zytzagoo
mi3.crew


Joined: 25 Aug 2003
Posts: 1842
Location: Zagreb, Hrvatska

PostPosted: 04.09.2009 15:23    Post subject: Add user to your forum ignore list Reply with quote

Klasika.
<form> elementu nedostaje enctype="multipart/form-data" atribut.
Bez toga form uploads ne funkcioniraju.

Code:
<form ... enctype="multipart/form-data">


EDIT: btw, editirao sam ti post gore da se site ne razlece zbog onog ogromnog regular
expressiona (koji je btw totalno nepotreban, ima puno laksih/boljih regexa za validaciju
email adrese).

_________________
[+]I[+]am[+]my[+]own[+]religion[+]
Back to top
View user's profile Send private message Visit poster's website Twitter profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Server-side All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group