0

Hi i have a working form below with my html and php code. the php code is the email.php but i need your help with this one How can i add the attachment file on my email form the form is already working without the file attachment how can i add it to the email.php so the file attachment will send along with the other fields take a look with the " class="custom-file-input" thats the input field for file attachment thanks

HTML FORM

<form id="aform"  method="POST" action="<?php bloginfo('stylesheet_directory'); ?>/email.php" class='ajaxform'> 
  <div class="form-group">
     <input type="name" class="form-control" name="first_name" id="name" placeholder="Name">
  </div>

  <div class="form-group">
      <input type="numberorcontact" name="phone" class="form-control" id="numberorcontact" placeholder="Email">
  </div>

  <div class="form-group">
      <textarea class="form-control" name="message" placeholder="Message:"id="message" required data-validation-required-message="Please enter a message."></textarea>
      <p class="help-block text-danger"></p>
  </div>

  <div class="form-group">
      <input  class="custom-file-input" class="file" type="file" name="fileToUpload" id="fileToUpload">
  </div>

  <button type="submit" name="submit" class="btn btn-default submit">SUBMIT</button>

</form>

PHP FORM

   <?php
ob_start();
$EmailFrom = "email.com";
$EmailTo = "email.com";
$Subject = "Contact form";
$first_name = Trim(stripslashes($_POST['first_name'])); 
$phone = Trim(stripslashes($_POST['phone'])); 
$message = Trim(stripslashes($_POST['message'])); 
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}
$Body = "";
$Body .= "name: ";
$Body .= $first_name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $phone;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";
    $success = mail($EmailTo, $Subject, $Body, "From: <$Email>");
    if ($success){
        header('Location: http://goldenjoyfranchising.com/');
            }
 ob_end_flush();
    ?>
  • 1
    If you want to add attachments, it would be best to use a more powerful mailing library like PHPMailer. – Barmar Mar 16 '17 at 22:16
  • Is there any way without using PHPmailer ? @Barmar – techno bisuit Mar 16 '17 at 22:25
  • You'll need to learn how to format MIME attachments in your code. I've been trying to find other questions that explain it, but they mostly tell people to use PHPMailer or SwiftMail. – Barmar Mar 16 '17 at 22:29

0 Answers0