我正在网站上使用PHPMailer,以便将用户信息发送到我的Outlook电子邮件中。电子邮件发送过程看起来一切正常,但是我面临的问题是,用户发送给我的所有信息都会通过Outlook发送到垃圾文件夹。这是我的代码:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once('private/initialize.php');
require_once('private/PHPMailer/src/Exception.php');
require_once('private/PHPMailer/src/PHPMailer.php');
require_once('private/PHPMailer/src/SMTP.php');
// SERVER SIDE VALIDATION
$errors = [];
$user = [];
$user['name'] = '';
$user['email'] = '';
$user['telephone'] = '';
$user['address'] = '';
$user['city'] = '';
$user['date_time'] = '';
$success = '';
$failed = '';
if (is_post_request()) {
$user = [];
$user['name'] = $_POST['name'] ? $_POST['name'] : '';
$user['email'] = $_POST['email'] ? $_POST['email'] : '';
$user['telephone'] = $_POST['telephone'] ? $_POST['telephone'] : '';
$user['address'] = $_POST['address'] ? $_POST['address'] : '';
$user['city'] = $_POST['city'] ? $_POST['city'] : '';
$user['date_time'] = $_POST['date_time'] ? $_POST['date_time'] : '';
$mail = new PHPMailer(true);
$email_body = "I hope it worked";
$user_email = $user['name'];
$mail->SMTPDebug = 0;
$mail->Port = 587;
$mail->Host = "smtp-mail.outlook.com";
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Username = 'example@outlook.com';
$mail->Password = '*********';
// Recipients
$mail->setFrom($user['email'], $user['name']);
$mail->addAddress('example@outlook.com', 'My name');
$mail->addReplyTo($user['email'], $user['name']);
// Content
$mail->IsHTML(true);
$mail->Subject = $user_email;
$mail->Body = $email_body;
if (!$mail->send()) {
$failed = "<div class='failed-message'>The email was not sent!</div>";
} else {
$success = "<div class='success-message'>Tack " . $user['name'] . " för din bokining. Vi återkommer snart.</div>";
$user = [];
$user['name'] = '';
$user['email'] = '';
$user['telephone'] = '';
$user['address'] = '';
$user['city'] = '';
$user['date_time'] = '';
}
}
else {
$user = [];
$user['name'] = '';
$user['email'] = '';
$user['telephone'] = '';
$user['address'] = '';
$user['city'] = '';
$user['date_time'] = '';
}
?>
我尝试了许多解决方案,但没有一个起作用,所以请告诉我该怎么做才能解决此问题。谢谢