J'ai créé un contact pour avec html et en utilisant le code PHP pour envoyer mon email et son fonctionnement bien mais j'ai un problème que je veux joindre le fichier et à envoyer aussi mais je ne ' sais pas comment tout le monde peut me aider .... et le code php est ci-dessous veux juste ajouter la pièce jointe des fichiers grâce à l'avancejoindre le fichier au formulaire de contact PHP
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<!-- Start PHP CODE -->
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// define Errors variables
$fnameErr = $lnameErr = $emailErr = $humanErr = $result = "" ;
if(isset($_POST['submit']))
{
// define contact form variables
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$design = $_POST['design'];
$country = $_POST['country'];
$comment = $_POST['comment'];
$human = $_POST['human'];
// define Errors variables
$fnameErr = $lnameErr = $emailErr = $humanErr = "" ;
// define Checks variables
$check1 = $check2 = $check3 = $check4 = "";
// define email variables
$to = '[email protected]';
$subject = 'Contact Form';
$message = 'From: '.$fname .$lname."\r\n".
'E-mail: '.$email."\r\n".
'Telephone: '.$tel."\r\n".
'Designation: '.$design."\r\n".
'Country Appled From: '.$country."\r\n".
'Message: '.$comment."\r\n";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers = "From:" .$email. "\n" ; \t
\t
// Let's do some checks \t
// Checking the First Name
if(empty($_POST["fname"])){
\t $fnameErr = "Name is Required";
}else{
\t $fname = test_input($_POST["fname"]);
\t // check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$fname)) {
$fnameErr = "Only letters and white space allowed";
}else{
\t \t $check1 = 1;
\t }
}
// Checking the Last Name \t
if(empty($_POST["lname"])){
\t $lnameErr = "Name is Required";
}else{
\t $lname = test_input($_POST["lname"]);
\t // check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$lname)) {
$lnameErr = "Only letters and white space allowed";
}else{
\t \t $check2 = 1;
\t }
}
//Checking the Email Adress
if(empty($_POST["email"])){
\t $emailErr = "Email is Required";
}else{
\t $email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}else{
\t \t $check3 = 1;
\t }
}
//Checking the Anti-Spam Question
if(empty($_POST["human"])){
\t $humanErr = "Please Enter the Answer";
}else{
\t if ($human != 4){
\t \t $humanErr = "Please check your answer";
\t }else{
\t \t $check4 = 1;
\t }
}
\t
// Emailing the Contents if all Checks are correct \t
if($check1 && $check2 && $check3 && $check4 == 1){
\t mail($to, $subject, $message, $headers);
\t $result = "Message Sent Sucessfully";
}else{
\t $result = "Message Can't be sent";
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<!-- END OF PHP CODE -->
<h2>Contact Form</h2>
<p><span style="color: red" >*Required field</span></p>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" enctype="multipart/form-data" accept-charset="UTF-8">
\t First Name:<input type="text" name="fname"><span style="color: red" >*</span> <?php echo $fnameErr ?> <br><br>
\t Last Name:<input type="text" name="lname"><span style="color: red" >*</span> <?php echo $lnameErr ?> <br><br>
\t E-mail:<input type="text" name="email"><span style="color: red" >*</span> <?php echo $emailErr ?> <br><br>
\t Telephone:<input type="text" name="tel"><br><br>
\t Designation:<select name="design">
\t \t <option value="Architectural Engineer">Architectural Engineer</option>
\t \t <option value="Structural Engineer">Structural Engineer</option>
\t \t <option value="Draughts-man">Draughts-man</option>
\t \t <option value="Receptionist">Receptionist</option>
\t \t <option value="Secertary">Secertary</option>
\t </select><br><br>
\t Country Applied From:<select name="country">
\t \t <option value="">Country...</option>
\t \t <option value="Afganistan">Afghanistan</option>
\t \t <option value="Albania">Albania</option>
</select><br><br>
\t Message:<textarea name="comment"></textarea> <br><br>
\t Upload Your Resume:<span style="color: red" >*</span><input type="file" name="uploaded_file"><br><br> \t
\t <label>*What is 2+2? (Anti-spam)</label>
\t <input name="human" placeholder="Type Here"><span style="color: red" >*</span><?php echo $humanErr ?><br><br>
\t <input type="submit" name="submit" value="Submit">
\t <input type="reset" value="Clear">
<?php echo $result ?>
</form><br>
</body>
</html>
Vous pouvez envoyer une photo ci-jointe en utilisant «pièce jointe» lors de l'envoi –