Php 无法通过电子邮件发送注册确认电子邮件
我已经设置了需要电子邮件验证的用户注册表。但是,代码无法生成电子邮件Php 无法通过电子邮件发送注册确认电子邮件,php,email,registration,Php,Email,Registration,我已经设置了需要电子邮件验证的用户注册表。但是,代码无法生成电子邮件 连接文件: $host="xxxx"; $dbname="xxxx"; $dbuser="xxxx"; $dbpassword="xxxx"; $con = mysqli_connect($host,$dbuser,$dbpassword,$dbname); $website_url="http://www.xxxx/email_activation/"; $sender_email="xxxx@yahoo.com";
连接文件:
$host="xxxx";
$dbname="xxxx";
$dbuser="xxxx";
$dbpassword="xxxx";
$con = mysqli_connect($host,$dbuser,$dbpassword,$dbname);
$website_url="http://www.xxxx/email_activation/";
$sender_email="xxxx@yahoo.com";
send_mail.php
function send_mail($to,$subject,$body)
{
require 'class.phpmailer.php';
$from = "from@yourwebsite.com";
$mail = new PHPMailer();
$mail->IsSMTP(true); // use SMTP
$mail->IsHTML(true);
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "tls://smtp.mail.yahoo.com"; // SMTP host
$mail->Port = 25; // set the SMTP port
$mail->Username = "xxxx@yahoo.com"; // SMTP username
$mail->Password = "xxxx"; // 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();
}
注册文件代码:
$activation = md5(uniqid(rand(), true));
include 'send_mail.php';
$message = " To activate your account, please click on this link: \n\n ";
$message .= $website_url . '/activate.php?email=' .urlencode($sender_email) .
"&key=$activation";
mail($email_address, 'Registeration Confirmation', $message, 'From:' .$sender_email);
您显示了一个
函数send\u mail()
,但您使用的是标准的phpmail()
函数吗?我看不出这3个代码示例是如何连接的。没有错误消息,唯一的错误是没有发送确认电子邮件。我是php新手,我遵循了博客中列出的步骤。你说得对,函数没有在任何地方调用。我应该在寄存器文件代码中的include语句之后添加函数吗?