0

I created a contact form with php and used xampp for this. For mail I used PHPMailer. But when I upload my files to ma host and test the page, it doesn't work. It comes shows a blanke page.

enter image description here

here is my mail.php code:

<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require 'vendor/autoload.php';



if(isset( $_POST['name']))
  $name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
if(isset( $_POST['vorname']))
  $name = filter_var($_POST['vorname'], FILTER_SANITIZE_STRING);
if(isset( $_POST['email']))
  $email = filter_var($_POST['email'], FILTER_SANITIZE_STRING);
if(isset( $_POST['message']))
  $message = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
if(isset( $_POST['subject']))
  $subject = filter_var($_POST['subject'], FILTER_SANITIZE_STRING);


$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'XXX';                                 // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'behar@zenuni.ch';                 // SMTP username
    $mail->Password = 'XXX';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

    //sender
    $mail->setFrom($email, $name);

    //empfänger
    $mail->addAddress('behar@zenuni.ch', 'Behar Zenuni');     // Add a recipient

    //body content
    $body = "<p><strong>Sie haben eine Nachricht erhlaten:</strong> <br><br> " . $message . "</p>";


    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = ' ' . $subject;

    $mail->Body    = $body;
    //$mail->AltBody = strip_tags($body);

    $mail->send();
    echo 'Message has been sent';
    //header("location: index.php?sent"); -> relocate to index.php
    header("location: thankyou.php");


} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}

and this is my index code:

 html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Zenuni Company</title>
  <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
  <link rel="stylesheet" href="bootstrap.css">
  <link rel="stylesheet" href="app.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
</head>

<body>
  <div class="container h-100" id="con1">
    <img src="">
    <div class="row">
      <div class="col-12">
          <div id="content">
            <h1>The Zenuni Company</h1>
            <h3>Contact Us</h3>
            <hr>
          </div>
      </div>
    </div>
  </div>  

<section class="section">
    <div class="container">      
        <div class="col-md-12 mb-md-10 mb-10">

            <form id="contact-form" name="contact-form" action="mail.php" method="POST">  

                <div class="row">                 
                  <div class="form-group col-md-3 offset-md-3">
                   <input class="form-control transparent-input" type="text" id="name" name="name" placeholder="Name" required>
                  </div>                 
                  <div class="form-group col-md-3">                        
                    <input class="form-control transparent-input" type="text" id="vorname" name="vorname" placeholder="Vorname" required>                        
                  </div>
                  <div class="form-group col-md-3 offset-md-3">                        
                    <input class="form-control transparent-input" type="email" id="email" name="email" placeholder="Email" required>                        
                  </div>
                  <div class="form-group col-md-3">                        
                    <input class="form-control transparent-input" type="text" id="subject" name="subject" placeholder="Subject" required>                        
                  </div>
                  <div class="form-group col-md-6 offset-md-3">                        
                    <textarea class="form-control transparent-input" type="text" id="message" name="message" cols="20" rows="10" placeholder="Enter your message" required></textarea>
                  </div>                  
                  <div class="form-group col-md-6 offset-md-3">
                    <button id="mybtn" type="submit" class="btn btn-primary">Send</button>
                  </div>                   
                </div>

            </form>

          </div>
        </div>
      </div>
</section>


 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>  
</body>
</html>

Can somebody help me what I am doring wrong, when uploading to my hostprovider? When I try my page via xampp, then it workes.

M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
zenubeh
  • 67
  • 1
  • 1
  • 9

0 Answers0