PHP电子邮件工作正常,但用户实际未收到
一旦提交了包含正确信息的表单,就会出现一条消息,通知用户电子邮件已发送。但是由于某些原因,用户没有收到电子邮件 我已经在网上查过了,但是没有用。有人能帮我解决这个问题吗 下面是HTML表单和PHP的代码PHP电子邮件工作正常,但用户实际未收到,php,html,phpmailer,Php,Html,Phpmailer,一旦提交了包含正确信息的表单,就会出现一条消息,通知用户电子邮件已发送。但是由于某些原因,用户没有收到电子邮件 我已经在网上查过了,但是没有用。有人能帮我解决这个问题吗 下面是HTML表单和PHP的代码 <form method="POST" action="contact.php"> <div class="row"> <div class="col-sm-6 form-gro
<form method="POST" action="contact.php">
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="name" name="name" placeholder="Name" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="email" name="email" placeholder="Email" type="email" required>
</div>
</div>
<textarea class="form-control inputStyle" id="comments" name="comments" placeholder="Comment" rows="6" required></textarea>
<br>
<div class="row">
<div class="col-sm-12 form-group">
<button class="btn btn-default pull-right" name="submit" type="submit">Send</button>
</div>
</div>
<!-- Contacting Support Team -->
<?php
if(isset($_POST['submit'])){
$email = $_POST['email'];
$name = $_POST['name'];
$comment = $_POST['comments'];
if(!empty($email) && !empty($name) && !empty($comment)){
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->Host = 'ssl://smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->Port = 465;
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '*****'; // SMTP username
$mail->Password = '*****'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = '*****';;
$mail->addAddress($email); // Name is optional
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Test';
$mail->Body = '$comment';
$mail->AltBody = '$comment';
if(!$mail->send()) {
echo '<div class="alert alert-danger alert-dismissible" id="myAlert">
<a href="#"class="close">×</a>
<strong> Email not sent </strong> Something went wrong.
</div>';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo '<div class="alert alert-success alert-dismissible" id="myAlert">
<a href="#"class="close">×</a>
<strong> Email sent!</strong> We will contact you as soon as possible.
</div>';
}
}
}
?>
</form>
发送
提前谢谢 您正在设置
$mail->SMTPSecure='tls'代码>
但端口465是Gmail SSL端口。587是TLS端口。因此,要么切换端口,要么更改为使用
$mail->SMTPSecure='ssl'代码>发送电子邮件并不保证收到电子邮件。代码可能正在发送,但可能是您设置的邮件服务器没有转发它,或者远程邮件服务器拒绝了它,或者用户的垃圾邮件过滤器将其删除或将其放在垃圾邮件文件夹中。可能有很多原因。您所能做的就是检查邮件的地址和格式是否正确,以及您是否通过邮件服务器进行了正确的身份验证。FWIW我从未见过像ssl://...
之前。有没有文件告诉你要这样做?嗨,阿德森,是的。我在互联网上搜索了很长一段时间,发现了一些类似这样的代码片段。我应该尝试更改它吗?首先尝试添加$mail->isSMTP()代码>确保PHPMailer知道使用SMTP的命令。同时设置$mail->SMTPDebug=3
从PHPMailer获取详细输出。如果这不起作用,那就试着丢掉ssl://
部分来取悦我。刚才还注意到您正在设置$mail->SMTPSecure='tls'代码>,但端口465是Gmail SSL端口。587是TLS端口。因此,要么切换端口,要么改为使用$mail->SMTPSecure='ssl'代码>。似乎这就是问题所在。你帮了很多忙,谢谢!