使用 bluehost 和 outlook 时 PHPmailer 出错
Getting an error with PHPmailer while using bluehost and outlook
这是我的 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;
}
?>
这是我的 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>
我在将电子邮件发送到我的 outlook 帐户时遇到问题。我要么让它重定向到适当的页面,要么我得到带有一堆错误的新网页。我只是想让表格给我发一封关于新订户的电子邮件……发生了什么事?这是错误页面:
我意识到 outlook/office 365,$mail->From == $mail->Username
我还没有想出如何使发件人地址适合我想要表达的内容。
SSL 也有效,为了获得正确的重定向,您需要将 $mail->SMTPDebug 设置为 0
这是我的 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;
}
?>
这是我的 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>
我在将电子邮件发送到我的 outlook 帐户时遇到问题。我要么让它重定向到适当的页面,要么我得到带有一堆错误的新网页。我只是想让表格给我发一封关于新订户的电子邮件……发生了什么事?这是错误页面:
我意识到 outlook/office 365,$mail->From == $mail->Username
我还没有想出如何使发件人地址适合我想要表达的内容。
SSL 也有效,为了获得正确的重定向,您需要将 $mail->SMTPDebug 设置为 0