Sending a mail with an attachment using php function sendmail
<p>i have a form like this :</p>

<p>this is 1.php</p>

<pre><code>&lt;form action="2.php" method="post"&gt;
Name: &lt;input type="text" name="name" /&gt;&lt;/br&gt;
Email: &lt;input type="text" name="email" /&gt;
&lt;input type="submit" value="Submit" /&gt;
</code></pre>

<p>than 2.php is like this :</p>

<pre><code>&lt;form action="3.php" method="post"&gt;
&lt;input type="hidden" name="name" value="&lt;?php echo $_POST['name'];?&gt;"/&gt;
&lt;input type="hidden" name="email" value="&lt;?php echo $_POST['email'];?&gt;"/&gt;
Telephone: &lt;input type="text" name="telephone" /&gt;&lt;/br&gt;
Location: &lt;input type="text" name="location" /&gt;
&lt;input type="submit" value="Submit" /&gt;
</code></pre>

<p>and the last one 3.php is like this:</p>

<pre><code>&lt;?php
    $error = "";
    if(isset($_POST['submit'])) {
        if(empty($_POST['email']) || empty($_POST['name'])) {
            $error .= 'There is an error. Retry.  &lt;br /&gt;';
        }
        if(!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) {
            $error .= 'E-mail is incorrect. &lt;br /&gt;';
        }       
        function sendmail() {
            $to = 'user@domain.tld';
            $name = "Name : " .$_POST['name'];
            $telephone = "Telephone : " . $_POST['telephone']. "";
            $location = "Location : " .$_POST['location'];
            $subiect = "Form from webpage";
            $body = 'form content: '. $name. "\n". $telephone. "\n\n" . $location. "\n\n". $from ;
            $from = "From: " . $_POST['email']. "";
            if(mail($to,$subiect,$body,$from)) {
              echo '&lt;p&gt;Thank you !&lt;/p&gt;&lt;br /&gt;';
            }else{
              echo '&lt;p&gt;Error with server&lt;/p&gt;';
            }
        }
        if($error == "") {
           sendmail();
        }
        echo "&lt;p&gt;".$error."&lt;/p&gt;";
    }            
?&gt;
</code></pre>

<p>My question is how can i introduce a <code>&lt;input type="file" name="file" id="file" /&gt;</code> in the 1st page when the user will be able to upload a photo and then on the 3.php page when he will hit the submit button that picture to be in the email</p>

<p>can anyone give me an example please ? Thank you !</p>
