0

I have contact form structure. With the following:

HTML:

   <form name="feedback_form" method="post" action="" class="feedback_form">
                                                <input type="text" name="field-name" value="İsim" title="İsim" class="field-name form_field">
                                                <input type="text" name="field-email" value="Email" title="Email" class="field-email form_field">
                                                <input type="text" name="field-subject" value="Başlık" title="Subject" class="field-subject form_field">
                                                <textarea name="field-message" cols="45" rows="5" title="Mesajınız..." class="field-message form_field">Mesajınız...</textarea>
                                                <input type="reset" name="reset" id="reset2" value="Temizle" class="feedback_reset">
                                                <input type="button" name="submit" class="feedback_go" id="submit2" value="Gönder">                                    

</form>  

And i added this codes for file upload:

<label for='uploaded_file'>Upload your picture:</label>
 <input type="file" name="uploaded_file">

I want, users can upload jpg, png, gif, bmp images via this label. But i don't know how can i reorganize my mail.php file?

mail.php:

<?php
header('Content-Type: text/html; charset=utf-8');

function sendFeedback($feedback_email, $feedback_msg, $feedback_name, $feedback_subject, $feedback_file) {


    /* EDIT THIS */
    $admin_email = "mymail@gmail.com";
    if ($feedback_subject == "Subject" || empty($feedback_subject) ) {
        $subj = "Email from your site";
    } else {
        $subj = $feedback_subject;
    }


    /* //EDIT THIS */


    $message = "
    <html>
    <head>
      <title>Websitenizin emaili</title>
    </head>
    <body>
        <p><a href='mailto:".$feedback_email."'>".$feedback_name."</a> send this message:</p>
        <p>".$feedback_msg."</p>
        <p>".$subject."</p>
    </body>
    </html>
    ";
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";

    if ($feedback_name!=="Name" && $feedback_email!=="Email" && !empty($feedback_email) && !empty($feedback_msg) && !empty($feedback_name) ) {
        if ($feedback_email == "mail_error") {
            echo "<span class='ajaxok'>Geçersiz email adresi.</span>";
        } else {            
            mail($admin_email, $subj, $message, $headers);
            echo "<span class='ajaxok'>Teşekkürler. Mesajınız gönderilmiştir.</span>";  
        }
    } else {
        echo "<span class='ajaxalert'>Lütfen zorunlu alanları doldurunuz.</span>";      
    }


}

sendFeedback($_POST['email'], $_POST['message'], $_POST['name'], $_POST['subject'], $_POST['file']);
?>
user1750573
  • 45
  • 1
  • 10
  • Well thank you, and welcome to SO. Did you forget to write the problem? There is an edit button to edit your question, I suggest to use it ;) – dbf Oct 31 '12 at 23:20
  • @dbf Sorry, edited my post :) – user1750573 Oct 31 '12 at 23:22
  • I agree that _not knowing_ is a problem, but SO isn't always the best solution for that .. – dbf Oct 31 '12 at 23:26
  • See http://stackoverflow.com/questions/3092821/php-send-e-mail-with-attachment or similar, there are plenty of guides how to allow email attachments in php. just search and learn! – jtheman Oct 31 '12 at 23:31

1 Answers1

0

First change the action to the directory where you have your mail.php file, as the code below. Then in the mail.php your gonna use something similiar to the PHP code below.

 <form name="feedback_form" method="post" action="mail.php" class="feedback_form">

There is something called

$_FILES['file']['type'];

You can use that like in the following code.

If you want more information or something, just reply or read more on this site

W3Schools file upload

<?php
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>