Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 25

Thread: mail form with upload file

  1. #11
    Join Date
    Jun 2007
    Posts
    72
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default

    To change where it who it goes to change:

    PHP Code:
    <?php
    // Read POST request params into global vars
    $to      $_POST['to'];
    To something like:
    PHP Code:
    <?php
    // Read POST request params into global vars
    $to      'me@mydomain.com';
    You can the also remove the 'To' input on the form

    Hope that helps
    Last edited by calumogg; 06-16-2008 at 01:59 PM.

  2. The Following User Says Thank You to calumogg For This Useful Post:

    chechu (06-16-2008)

  3. #12
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    This is what I have in html:
    Code:
    <script type="text/JavaScript">
    function clearDefault(el) {
    if (el.defaultValue==el.value) el.value = ""
    }
    </script>
    
    <form action="testcontact.php" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="action" value="send">
    <input type="text" name="from" value=" your name" onfocus="clearDefault(this)" style="border-top:0px; border-left: 1px dotted #cc6600; border-right:0px; border-bottom: 1px dotted #cc6600; width:150px">
    <br>
    <input type="text" name="email" value=" your email adress" onfocus="clearDefault(this)" style="border-top:0px; border-left: 1px dotted purple; border-right:0px; border-bottom: 1px dotted purple; width:150px;">
    <br>
    <input type="file" name="fileatt" style="border-top:0px; border-left: 1px dotted purple; border-right:0px; border-bottom: 1px dotted purple; width:150px;">
    <br>
    <textarea name="message" style="border-top:0px; border-left:1px dotted #0066cc; border-right:0px; border-bottom: 1px dotted #0066cc; width:150px; height:63px"> message</textarea>
    <br>
    &nbsp;&nbsp;&nbsp; <input type="image" src="images/sendarrow.gif" value="send">
    &nbsp;&nbsp;&nbsp; <img src="images/clear.gif" onclick="document.getElementById('form1').reset();" style="cursor:pointer">
    </form>
    And this is the php:
    Code:
    <?php
    // Read POST request params into global vars
    $to      = 'info@mysite.com';
    $from    = $_POST['from'];
    $email   = $_POST['email'];
    $message = $_POST['message'];
    
    // Obtain file upload vars
    $fileatt      = $_FILES['fileatt']['tmp_name'];
    $fileatt_type = $_FILES['fileatt']['type'];
    $fileatt_name = $_FILES['fileatt']['name'];
    
    $headers = "From: $from";
    
    if (is_uploaded_file($fileatt)) {
      // Read the file to be attached ('rb' = read binary)
      $file = fopen($fileatt,'rb');
      $data = fread($file,filesize($fileatt));
      fclose($file);
    
      // Generate a boundary string
      $semi_rand = md5(time());
      $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
      
      // Add the headers for a file attachment
      $headers .= "\nMIME-Version: 1.0\n" .
                  "Content-Type: multipart/mixed;\n" .
                  " boundary=\"{$mime_boundary}\"";
    
      // Add a multipart boundary above the plain message
      $message = "This is a multi-part message in MIME format.\n\n" .
                 "--{$mime_boundary}\n" .
                 "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
                 "Content-Transfer-Encoding: 7bit\n\n" .
                 $message . "\n\n";
    
      // Base64 encode the file data
      $data = chunk_split(base64_encode($data));
    
      // Add file attachment to the message
      $message .= "--{$mime_boundary}\n" .
                  "Content-Type: {$fileatt_type};\n" .
                  " name=\"{$fileatt_name}\"\n" .
                  //"Content-Disposition: attachment;\n" .
                  //" filename=\"{$fileatt_name}\"\n" .
                  "Content-Transfer-Encoding: base64\n\n" .
                  $data . "\n\n" .
                  "--{$mime_boundary}--\n";
    }
    
    // Send the message
    $ok = @mail($from, $email, $message, $headers);
    if ($ok) {
      echo "<p>Mail sent! Yay PHP!</p>";
    } else {
      echo "<p>Mail could not be sent. Sorry!</p>";
    }
    ?>
    Then mail never gets sent. In orange you can see the adjustments I made; obviously wrong. What is wrong ?
    See it here in action: http://www.cecicasariego.com/testcontact.html

  4. #13
    Join Date
    Jun 2007
    Posts
    72
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default

    Hmm ok try this (I havent tested this):

    PHP Code:
    <?php
    // Read POST request params into global vars
    $to      'info@mysite.com';
    $from    $_POST['from'];
    $email   $_POST['email'];
    $message $_POST['message'];

    // Obtain file upload vars
    $fileatt      $_FILES['fileatt']['tmp_name'];
    $fileatt_type $_FILES['fileatt']['type'];
    $fileatt_name $_FILES['fileatt']['name'];

    $headers "From: $email ";

    if (
    is_uploaded_file($fileatt)) {
      
    // Read the file to be attached ('rb' = read binary)
      
    $file fopen($fileatt,'rb');
      
    $data fread($file,filesize($fileatt));
      
    fclose($file);

      
    // Generate a boundary string
      
    $semi_rand md5(time());
      
    $mime_boundary "==Multipart_Boundary_x{$semi_rand}x";
      
      
    // Add the headers for a file attachment
      
    $headers .= "\nMIME-Version: 1.0\n" .
                  
    "Content-Type: multipart/mixed;\n" .
                  
    " boundary=\"{$mime_boundary}\"";

      
    // Add a multipart boundary above the plain message
      
    $message "This is a multi-part message in MIME format.\n\n" .
                 
    "--{$mime_boundary}\n" .
                 
    "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
                 
    "Content-Transfer-Encoding: 7bit\n\n" .
                 
    $message "\n\n";

      
    // Base64 encode the file data
      
    $data chunk_split(base64_encode($data));

      
    // Add file attachment to the message
      
    $message .= "--{$mime_boundary}\n" .
                  
    "Content-Type: {$fileatt_type};\n" .
                  
    " name=\"{$fileatt_name}\"\n" .
                  
    //"Content-Disposition: attachment;\n" .
                  //" filename=\"{$fileatt_name}\"\n" .
                  
    "Content-Transfer-Encoding: base64\n\n" .
                  
    $data "\n\n" .
                  
    "--{$mime_boundary}--\n";
    }

    // Send the message
    $ok = @mail($to'SUBJECT'$message$headers);
    if (
    $ok) {
      echo 
    "<p>Mail sent! Yay PHP!</p>";
    } else {
      echo 
    "<p>Mail could not be sent. Sorry!</p>";
    }
    ?>
    HTML Code:
    <script type="text/JavaScript">
    function clearDefault(el) {
    if (el.defaultValue==el.value) el.value = ""
    }
    </script>
    
    <form action="testcontact.php" method="POST" enctype="multipart/form-data">
    	<p>
    	<input type="hidden" name="action" value="send">
    	</p>
    	<p>
    		<input type="text" name="from" id="from" value="your name" onfocus="clearDefault(this)" style="border-top:0px; border-left: 1px dotted #cc6600; border-right:0px; border-bottom: 1px dotted #cc6600; width:150px">
    		<br>
    		<input type="text" name="email" id="email" value=" your email adress" onfocus="clearDefault(this)" style="border-top:0px; border-left: 1px dotted purple; border-right:0px; border-bottom: 1px dotted purple; width:150px;">
    		<br>
    		<input type="file" name="fileatt" id="fileatt" style="border-top:0px; border-left: 1px dotted purple; border-right:0px; border-bottom: 1px dotted purple; width:150px;">
    		<br>
    		<textarea name="message" id="message" style="border-top:0px; border-left:1px dotted #0066cc; border-right:0px; border-bottom: 1px dotted #0066cc; width:150px; height:63px"> message</textarea>
    		<br>
    	&nbsp;&nbsp;&nbsp; 
    		<input type="image" src="images/sendarrow.gif" value="send">
    	&nbsp;&nbsp;&nbsp; <img src="images/clear.gif" onclick="document.getElementById('form1').reset();" style="cursor:pointer">
    		</p>
    </form>

  5. #14
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    It works, but with the following remarks:
    - the email and name and subject areas need to be filled in; now the mail gets sent without anything filled in.
    - I know the email adress of the sender, but not his name (although requested)
    - their is no confirmation mail sent

    Is it possible to have the above php, mixed with the follwing one:
    Code:
    <?php
    
    if ($_POST["action"] == "send"){
    
    if ($_POST[name] != " your name" and $_POST[name] != "" and $_POST[email] != " your e-mail adress" and $_POST[email] != "" and $_POST[message] != "") { 
    mail ("info@site.com", "via website (EN)", 
    "
    Name: ".$_POST['name']."
    E-mail: ".$_POST['email']."
    Message: ".$_POST['message']."
    
    ",
    "From: ".$_POST['name']." <".$_POST['email'].">");
    
    $subject = "your message to Ceci Casariego"; 
    
    $msg = "
    
    This is an automatically sent email. Please do not reply.
    
    Dear $_POST[name],
    
    Thanks for your message to Ceci.
    She will get back to you as soon as possible.
    
    This was your message:
    $_POST[message] 
    ";  
    
    mail($_POST[email], $subject, $msg); 
    
    echo 'Thanks ! <br>Your message has been sent,<br> and you will receive a confirmation mail. <br><br> We will get back to you as soon as we can.<br>&nbsp;<br><br>';
    
    }
    
    else{
    echo 'Please fill in all data !<br><br>Your name, email adress and message <br>are mandatory fields.<br><br><a href="contact.html"><font color="#565656;">[again please]</font></a><br>&nbsp;<br>';
    }
    }
    ?>
    And how can I send more than one attachment in the same email ?
    Last edited by chechu; 06-16-2008 at 08:02 PM.

  6. #15
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    It is starting to become a real puzzle, therefore I'd like to put everything together, so that hopefully an expert can make it work:
    This is what I need the form to do:

    - fields: name, email, upload image, message
    - name, email and message are obligatory fields
    - possibility to upload attachments (mainly images)
    - when one image is uploaded, link appears under it, asking to add another image, or delete the previous
    - possibility to send max. 10 attachments per email
    - when sent, a confirmation appears
    - if error in the fields, not being sent to another page saying there's an error, but remaining at the same page, where the errors are put in the html-form (showing f.ex. with an asterisk or image what is missing)
    - the confirmation shows if there was an attachment or no (f.ex. message (without attachment, with 5, 8 attachments) sent)
    - a confirmation email is sent to the poster

    Can anyone put this all together in one php form, please ??
    I know it is a lot to ask, but I also know we have real experts in this forum !
    Last edited by chechu; 06-19-2008 at 10:07 AM.

  7. #16
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

  8. #17
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    Is it also posible, besides the above, to add a 'send me a copy' option ?

  9. #18
    Join Date
    Jun 2008
    Posts
    7
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default This may be blasphemous but ...

    I'm a PHP newb who is trying to learn more about coding. In the past, I've used a utility called FormsToGo. It can generate the PHP code (ASP and Perl too) and provides lots of options for recipients, conformation emails, attachments, security and more. It may be easier to let FTG generate your code instead of killing yourself trying to figure out how to make your own code work. You could then examine the code FTG generates to see how it's done. I believe the publisher offers a 30 free trial.

    Here is a link to the product's features page:

    http://www.bebosoft.com/products/formstogo/features.php

    Hope this is helpful.

  10. The Following User Says Thank You to jrizzo For This Useful Post:

    chechu (06-28-2008)

  11. #19
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    I tried the package you suggested, but I cannot find the requiered features in it.
    I' d really have to stick to the needs described above, as I cannot play around with it.
    Can anyone help me with this, please ?

  12. #20
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    I am getting closer ! I adapted a script, and this is the result: http://www.cecicasariego.com/testcontact2.php, but there is an error, and I still need the following features:

    - possibility to upload attachments (mainly images)
    - when one image is uploaded, link appears under it, asking to add another image, or delete the previous
    - possibility to send max. 10 attachments per email
    - the confirmation shows if there was an attachment or no (f.ex. message (without attachment, with 5, 8 attachments) sent)

    Can anyone have a look what causes the error:
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /customers/cecicasariego.com/cecicasariego.com/httpd.www/testcontact2.php:8) in /customers/cecicasariego.com/cecicasariego.com/httpd.www/testcontact2.php on line 145
    and how to add the other functions, please. The current code (without the captcha) is in the next reply.
    Last edited by chechu; 07-05-2008 at 08:55 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •