PHPmailer无法从表单中获取电子邮件


Not getting emails from form with PHPmailer

我正在尝试使用php邮件库与电子邮件激活表单注册页面。在填写完表格并提交我收到的页面后,我没有收到任何错误。我已经检查了我的电子邮件很多次,我似乎没有收到任何邮件。既然没有错误,我不确定还需要寻找什么。以前有人遇到过类似的问题吗?会不会是gmail的问题?

Send_mail.php

<?php
function Send_Mail($to,$subject,$body)
{
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$from       = "batoosay@gmail.com";
$mail       = new PHPMailer();
$mail->IsSMTP(true);            // use SMTP
$mail->IsHTML(true);
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "tls://smtp.gmail.com"; // SMTP host
$mail->Port       =  465;                    // set the SMTP port
$mail->Username   = "batoosay@gmail.com";  // SMTP  username
$mail->Password   = "password";  // SMTP password
$mail->SetFrom($from, 'From Name');
$mail->AddReplyTo($from,'From Name');
$mail->Subject    = $subject;
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, $to);
$mail->Send(); 
}
?>
这里是index。php
<?php
include 'db.php';
$msg='';
if(!empty($_POST['email']) && isset($_POST['email']) &&  !empty($_POST['password']) &&  isset($_POST['password']) )
{
// username and password sent from form
$email=mysqli_real_escape_string($connection,$_POST['email']);
$password=mysqli_real_escape_string($connection,$_POST['password']);
// regular expression for email check
$regex = '/^[_a-z0-9-]+('.[_a-z0-9-]+)*@[a-z0-9-]+('.[a-z0-9-]+)*('.[a-z]{2,4})$/';

if(preg_match($regex, $email))
{ 
$password=md5($password); // encrypted password
$activation=md5($email.time()); // encrypted email+timestamp
$count=mysqli_query($connection,"SELECT uid FROM users WHERE email='$email'");
// email check
if(mysqli_num_rows($count) < 1)
{
mysqli_query($connection,"INSERT INTO users(email,password,activation) VALUES('$email','$password','$activation')");
// sending email
include 'Send_Mail.php';
$to=$email;
$subject="Email verification";
$body='Hi, <br/> <br/> We need to make sure you are human. Please verify your email and get started using your Website account. <br/> <br/> <a href="'.$base_url.'activation/'.$activation.'">'.$base_url.'activation/'.$activation.'</a>';

Send_Mail($to,$subject,$body);
$msg= "Registration successful, please activate email."; 
}
else
{
$msg= 'The email is already taken, please try new.'; 
}

}
else
{
$msg = 'The email you have entered is invalid, please try again.'; 
}

}
// HTML Part
?>

请根据PHPMailer提供的gmail示例编写代码,因为它提供了正确的设置。

您在Host属性中使用的语法很好(虽然不像设置SMTPSecure = 'tls'那样常见),但是您使用错误的端口来使用STARTTLS(这是当您指定tls时使用的)-您需要使用Port = 587。这可能就是你迟到的原因。