Here's my php:
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");
$email = $_POST['email'];
require 'Exception.php';
require 'PHPMailer.php';
require 'SMTP.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer(true);
try {
//Server settings
$mail->CharSet="UTF-8";
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.office365.com';
$mail->SMTPAuth = true;
$mail->Username = 'me@vrifyhealth.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->From = "subscriber@vrifyhealth.com";
$mail->FromName = "Vrify Health Subscriber";
$mail->addAddress("me@vrifyhealth.com", "me");
$mail->addAddress("other@gmail.com");
//Content
$mail->isHTML(true);
$mail->Subject = 'New subscriber';
$mail->Body = 'New email subscriber for Vrify Health: $email</b>';
if($mail->send()){
header('Location: thank-you.html'); // redirect to 'thank you' page
}
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
?>
Here's my html:
<form action="mail.php" method="POST">
<div class="email-box">
<input class="tbox" id="email_box" name="email" type="email" style="cursor: pointer;" placeholder="Enter your email">
<button class="btn" id="email_btn" type="submit" name="button">Subscribe</button>
</div>
</form>
<script language="JavaScript">
var frmvalidator = new Validator("contactform");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("email","email",
"Please enter a valid email address");
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/validate.js/0.13.1/validate.min.js"></script>
<script>
const constraints = {
name: {
presence: {allowEmpty: false}
},
email: {
presence: {allowEmpty: false},
email: true
},
message: {
presence: {allowEmpty: false}
}
};
const form = document.getElementById('contact-form');
form.addEventListener('submit', function (event) {
const formValues = {
name: form.elements.name.value,
email: form.elements.email.value,
message: form.elements.message.value
};
const errors = validate(formValues, constraints);
if (errors) {
event.preventDefault();
const errorMessage = Object
.values(errors)
.map(function (fieldValues) {
return fieldValues.join(', ')
})
.join("\n");
alert(errorMessage);
}
}, false);
</script>
I am having an issue having the email sent to my outlook account. I either get it to redirect to the appropriate page, or I get new webpage with a bunch of errors. I'm just trying to have the form send me an email with the new subscriber...what's going on? Here's the error page:
I realized that with outlook/office 365, $mail->From == $mail->Username
I have yet to figure out how to make the from address tailored to what I want it to say.
Also SSL works and in order to get a proper redirect you need to set $mail->SMTPDebug to 0