gpt4 book ai didi

php - 无法使用 PHPmailer 从表单获取电子邮件

转载 作者:行者123 更新时间:2023-11-29 12:02:38 24 4
gpt4 key购买 nike

我正在尝试使用 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

?>

顺便说一句,它加载了很长时间。

最佳答案

请将您的代码基于 the gmail example provided with PHPMailer ,因为它提供了正确的设置。

您在 Host 属性中使用的语法很好(尽管不如设置 SMTPSecure = 'tls' 常见),但您使用了错误的语法使用 STARTTLS 的端口(这是您指定 tls 时使用的端口) - 您需要使用 Port = 587。这可能就是导致您延迟的原因。如果这不起作用,请阅读 the troubleshooting guide .

关于php - 无法使用 PHPmailer 从表单获取电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32112956/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com