0

This is my code. Phpmailer does work with a sample piece of code I used. Implementing the mailer code into the contact page is where my trouble began. I'll be forever in your debt if you can help, this is a team project and the rest of the team are held back because of this issue.

<!DOCTYPE html>
<html>

<link rel="stylesheet" type="text/css" href="sicknessStyling.css">
<body>
<div class="topnav">
  <a href="main.html">View Rota</a>
  <a href="ShiftSwap.html">Shift Swap</a>
  <a href="sickness.html" >Declare Sickness</a>
  <a href="dispHoliday.html">Holiday Time</a>
</div>

<center>
  <h1>Email Management Concerning Sickness</h1>

<div class="Sickform">

    <form action="" method="post">

    E-mail:<br>
    <input name="email" type="email"><br>

    Subject: <br>
    <input name="subject" type="text"/><br>

    Message:<br>
    <textarea name="comment" rows="5" cols="40" placeholder="Your message here..." wrap="hard" >
    </textarea><br>
    <br>


    <button id="send" type="submit"> Send </button>
    <button id="reset" type="reset"> Reset </button>
  </form>

</div>
</center>

This is the PHP code I've been using. Tried all sorts of different methods but no luck so far.

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

if(isset($_POST['send'])){
    // Import PHPMailer classes into the global namespace
    // These must be at the top of your script, not inside a function

    $email = $_REQUEST['email'];
    $message = $_REQUEST['comment'];
    $sunject = $_REQUEST['subject'];

    //Recipients
    $mail->From = $email;
    $mail->addAddress('teamproject.hotelmanager@gmail.com', 'Michael Admin');     // Add a recipient
    $mail->AddReplyTo = $email;

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

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

$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 = 'smtp.gmail.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'teamproject.hotelmanager@gmail.com';                 // SMTP username
    $mail->Password = 'XXXXXX';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to
    $mail->SMTPOptions = array(
                    'ssl' => array(
                        'verify_peer' => false,
                        'verify_peer_name' => false,
                        'allow_self_signed' => true
                    )
                );


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

</body>
</html>

0 Answers0