I've updated this code, using PHPMailer. The code now works and sends through the form to any email address I wish as long as I have the correct host setup in the PHP. This is GREAT. But, it doesn't direct me to my thank you page: header("Location: http://strawberryletting.co.uk/new_form/thank_you.html");
it sends the email fine, along with the correct information, but once the user selects the submit button
they stay on the PHP page with a lot of written jargon. Please see updated PHP below:
PHP:
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump"); // Look for errors and report errors - if there are any
$name = $_POST["name"]; // Declare variables - inputted from HTML form
$email = $_POST["email"];
$tel = $_POST["tel"];
$msg = $_POST["msg"];
require("PHPMailer/src/PHPMailer.php"); // Call files required for the phpmailer code from our folder directory
require("PHPMailer/src/Exception.php");
require("PHPMailer/src/SMTP.php");
$mail = new PHPMailer\PHPMailer\PHPMailer(true);
$mail->isSMTP(); // Simple mail transfer protocol
$mail->SMTPDebug = 2; // 1 - 4 use 2 - most useful response
$mail->SMTPAuth = true; // enable the SMTP authentication
$mail->Host = 'smtp.live.com'; // SMTP server and backup server
$mail->Username = 'billy.farroll@hotmail.com';
$mail->Password = 'PASSWORD';
$mail->SMTPSecure = 'tls'; // enable encryption - accepts TLS also
$mail->Port = 587; // port to connect - SSL 465 TLS TLS 587 - likely port numbers - 25, 465 or 587
$mail->setFrom('billy.farroll@hotmail.com', 'Billy Farroll'); // This is where the email will come from
$mail->addAddress('billy@strawberrymarketing.com','Billy Farroll'); // This is where the email will be sent to
$mail->addReplyTo("$email","$name");
$mail->isHTML(true);
$mail->Subject = 'TEST1';
$mail->Body = "$msg";
if (!$mail->send()){ // Send the message
echo 'Message Failed';
} else {
header("Location: http://strawberryletting.co.uk/new_form/thank_you.html"); // Take me to Thank you page
}
?>
HTML:
<div class="container">
<div class="row">
<div class="col-lg-12">
<section id="contact">
<form action="enquiry_new.php" method="post">
<div class="field name-box">
<input type="text" id="name" name="name" placeholder="Who Are You?" tabindex="1" required>
<label for="name">Name</label>
<span>Done</span>
</div>
<div class="field email-box">
<input type="text" id="email" name="email" placeholder="name@email.com" tabindex="2" required>
<label for="email">Email</label>
<span>Done</span>
</div>
<div class="field tel-box">
<input type="text" id="tel" name="tel" placeholder="Telephone Number" tabindex="3" required>
<label for="tel">Mobile</label>
<span>Done</span>
</div>
<div class="field msg-box">
<textarea id="msg" name="msg" rows="4" placeholder="What's Up?" tabindex="4" required></textarea>
<label for="msg">Message</label>
<span>Done</span>
</div>
<input class="button" type="submit" value="Send" />
</form>
</section>
</div>
</div>
</div>