1

HTML Form code

 <form enctype="multipart/form-data" method="post" id="terminvereinbarung" action="terminvereinbarung.php">
        <h2 style="font-family: Raleway-Light; font-weight: 300;">Jetzt Beratungstermin vereinbaren (bitte angeben, wo das Beratungsgespräch stattfinden soll)</h2>
        <div class="row">
          <div class="col-xs-12 col-sm-5 col-md-5 col-lg-5">
            <label><input placeholder="*Vorname" id="mail-name" type="text" name="vorname" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required simpleInput" style="font-family: Raleway-Light; font-weight: 300; font-size: 14px;"  required /></span><span></span></label> 
                  </div>
          <div class="col-xs-12 col-sm-5 col-md-5 col-lg-5">
            <label><input placeholder="*Nachname" id="mail-lastname" type="text" name="nachname" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-email wpcf7-validates-as-required wpcf7-validates-as-email simpleInput" style="font-family: Raleway-Light; font-weight: 300; font-size: 14px;" required /></span><span></span></label>
          </div>
        </div>
        <div class="emptySpace55 emptySpace-md0"></div>
        <div class="row">
          <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
            <label><input placeholder="*Strasse und Hausnummer" id="mail-adresse" type="text" name="addresse" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required simpleInput" style="font-family: Raleway-Light; font-weight: 300; font-size: 14px;"  required /></span><span></span></label>
          </div>
          <div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
            <label><input maxlength="5" minlength="4" placeholder="*Postleitzahl" id="mail-zipcode" type="text" name="postalCode" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required simpleInput" style="font-family: Raleway-Light; font-weight: 300; font-size: 14px;"  required /></span><span></span></label>
            </div>
          <div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
            <label><input placeholder="*Ort" id="mail-ort" type="text" name="ortschaft" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required simpleInput" style="font-family: Raleway-Light; font-weight: 300; font-size: 14px;"  required /></span><span></span></label>
            </div>
          </div>
          <div class="emptySpace55 emptySpace-md0"></div>
        <div class="row">
          <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
            <label><input placeholder="*Email" id="mail-email" type="email" name="email" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required simpleInput" style="font-family: Raleway-Light; font-weight: 300; font-size: 14px;"  required /></span><span></span></label>
          </div>
          <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
            <label><input placeholder="*Telefon" id="mail-phone" type="text" name="telefon" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required simpleInput" style="font-family: Raleway-Light; font-weight: 300; font-size: 14px;"  required /></span><span></span></label>
            </div>
          </div>
        <div class="emptySpace55 emptySpace-md0"></div>
        <div class="row">
          <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
                <label><input placeholder="*Ihr Wunschtermin" id="basicDate" type="text" name="datum" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required simpleInput" style="font-family: Raleway-Light; font-weight: 300; font-size: 14px;" data-input required /></span><span></span></label>
              </div>
          <div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
            <label><input placeholder="*Ort der Beratung" id="mail-beratung" type="text" name="beratung" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required simpleInput" style="font-family: Raleway-Light; font-weight: 300; font-size: 14px;" data-input required /></span><span></span></label>
            </div>
        </div>
        <div class="emptySpace55 emptySpace-md0"></div>
        <label class="textArea"><textarea placeholder="Weitere Informationen an uns" id="mail-message" name="message" cols="40" rows="10" class="wpcf7-form-control wpcf7-textarea simpleInput" style="font-family: Raleway-Light; font-weight: 300; font-size: 14px;" required></textarea></span><span></span></label>
        <div class="emptySpace55 emptySpace-md0"></div>
          <legend>Dateiübertragung</legend>
          <div class="clearfix">
            <p>Bitte laden Sie Ihre Details, Skizzen, Fotos etc. hoch, damit wir uns besser auf das Beratungsgespräch vorbereiten können.</p>
          </div>
          <div class="emptySpace10 emptySpace-md0"></div>
          <div class="row">
            <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
                <div class="input-file-container">  
                    <input class="input-file" id="my-file" type="file" name="file">
                    <label tabindex="0" for="my-file" class="input-file-trigger">Select a file...</label>
                  </div>
                  <p class="file-return"></p>
            <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
              </div>
            </div>
          </div>
        </fieldset>
        <div class="emptySpace55 emptySpace-md0"></div>
        <fieldset id="terminvereinbarung-fieldset-2" class="form-group">
          <legend>Datenschutz</legend>
          <div class="clearfix">
            <div id="c122" class="frame frame-default  frame-type-html frame-layout-0 frame-space-before-none frame-space-after-none"><a data-fancybox data-src="#iframe" href="javascript:;"></a></div>
          </div>
          <div class="emptySpace10 emptySpace-md0"></div>
          <button id="modal-btn" class="hochladen-btn">Datenschutzerklärung</button>


          <div class="clearfix">
            <div class="container" id="iframe">
              <div id="c123" class="frame frame-default  frame-type-text frame-layout-104 frame-space-before-none frame-space-after-none">
              </div>
            </div>
          </div>
          <div class="emptySpace55 emptySpace-md0"></div>
          <label class="topcoat-checkbox">
              <input type="checkbox" name="checkbox" value="checkbox" required>
              <div class="topcoat-checkbox__checkmark"></div>
            </label>
            <span class="help-block">Ich bin damit einverstanden, dass meine oben genannten Daten zur Bearbeitung und Durchführung des Beratungstermins gespeichert werden. Ich habe die aktuelle Datenschutzerklärung gelesen und akzeptiere sie. Diese Einwilligung kann ich jederzeit mit Wirkung für die Zukunft widerrufen, indem ich mich an info(at)duschfit.ch wende. (Pflichtfeld)</span>
        </fieldset>
      </div>
        <div class="emptySpace55 emptySpace-md0"></div>
        <div class="btnWrapper textRight">
          <div class="button"><a class="btn" onclick="sweetalertclick()" style="color: black !important;">Senden</a><input id="mail-submit" type="submit" name="submit" value="Send Message" class="wpcf7-form-control wpcf7-submit" /></div>
        </div>
      </form>

this is the php code i have put together so far

 <?php


$vorname = $_POST['vorname'];  
$nachname = $_POST['nachname'];  
$addresse = $_POST['addresse'];  
$postalCode = $_POST['postalCode'];  
$ortschaft = $_POST['ortschaft'];  
$mailFrom = $_POST['email'];  
$telefon = $_POST['telefon'];  
$datum = $_POST['datum'];  
$beratung = $_POST['beratung'];  
$file = $_POST['file'];  
$checkbox = $_POST['checkbox'];
$message = $_POST['message'];

$mailTo = "admin@duschfit.ch";
$headers = "From: ".$mailFrom;
$txt = "Vorname:".$_POST["vorname"]. "Name:".$_POST["nachname"]. "Addresse:".$_POST["addresse"]. "Postleitzahl:".$_POST["postalCode"]. 
        "Ortschaft:".$_POST["ortschaft"]. "Telefon:".$_POST["telefon"]. "Datum:".$_POST["datum"]. "Beratungsort:".$_POST["beratung"]. "Message Posted:".$_POST["message"];

mail($mailTo, $subject, $txt, $headers);
header("Location: https://duschfit.ch/terminvereinbarung?mailsend");
$uploadOk = 1;

$currentDir = getcwd();
    $uploadDirectory = "/uploads/";

    $errors = []; // Store all foreseen and unforseen errors here

    $fileExtensions = ['jpeg','jpg','png']; // Get all the file extensions

    $fileName = $_FILES['file']['name'];
    $fileSize = $_FILES['file']['size'];
    $fileTmpName  = $_FILES['file']['tmp_name'];
    $fileType = $_FILES['file']['type'];
    $fileExtension = strtolower(end(explode('.',$fileName)));

    $uploadPath = $currentDir . $uploadDirectory . basename($fileName); 

    if (isset($_POST['submit'])) {

        if (! in_array($fileExtension,$fileExtensions)) {
            $errors[] = "This file extension is not allowed. Please upload a JPEG or PNG file";
        }

        if ($fileSize > 2000000) {
            $errors[] = "This file is more than 2MB. Sorry, it has to be less than or equal to 2MB";
        }

        if (empty($errors)) {
            $didUpload = move_uploaded_file($fileTmpName, $uploadPath);

            if ($didUpload) {
                echo "The file " . basename($fileName) . " has been uploaded";
            } else {
                echo "An error occurred somewhere. Try again or contact the admin";
            }
        } else {
            foreach ($errors as $error) {
                echo $error . "These are the errors" . "\n";
            }
        }
    }

?>

Everything gets sent, except the attachment files which are missing from the mailbox.

Im not using phpmailer now as I want to understand this part of PHP before i move to the mailer library.

I also tried to add boundaries but I end up getting an internal ERROR.

Kevin Hernandez
  • 1,141
  • 1
  • 19
  • 38

0 Answers0