【发布时间】:2015-08-20 08:13:54
【问题描述】:
我正在尝试使用 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
?>
顺便说一句,它加载了很长时间。
【问题讨论】:
-
确保 google smtp 服务器设置正确。 digitalocean.com/community/tutorials/….
-
Apache 配置检查。您必须配置 SMTP 服务器 apache。
-
如您所见,设置正确。我在托管中对其进行了测试,他们告诉我此功能在他们的服务器上启用