php - 在php中注册后无法向用户发送电子邮件
问题描述
注册后我无法向用户发送电子邮件。数据已成功插入数据库,但注册后电子邮件不会发送给用户,该用户已成功注册。
<?php
include 'includes/db.php';
if(isset($_POST['submit_user']))
{
$email = $_POST['email'];
$phone_no=$_POST['phone_no'];
$check=mysqli_query($conn,"select * from users where user_email='$email' OR user_phone_no='$phone_no' ");
$checkrows=mysqli_num_rows($check);
if($checkrows>0)
{
$msg = 'Email or Phone Number Already Exists';
$msgclass = 'bg-danger';
}
else
{
// checking password is matching with confirm password or not
if($_POST['password'] == $_POST['con_password'])
{
$date = date('Y-m-d h:i:s');
$user_role='employee';
$password = mysqli_real_escape_string($conn,$_POST['password']);
$password=md5($password);
$ins_sql = "INSERT INTO users (first_name, user_gender, user_phone_no,user_email, user_password, user_date,user_role,username) VALUES ('$_POST[first_name]', '$_POST[user_gender]','$_POST[phone_no]', '$_POST[email]', '".$password."', '$date','$user_role','$_POST[email]')";
$run_sql = mysqli_query($conn,$ins_sql);
//$msg = 'Registration is Successful. You can login to start the Online Application.';
//$msgclass = 'bg-success';
$email = $_POST['email'];
$sel_sql = "select * from users where user_email='$email'";
$run_sel_sql = mysqli_query($conn,$sel_sql);
while($rows1 = mysqli_fetch_assoc($run_sel_sql)){
$to = $rows1['user_email'];
}
//$text="Amounts has been Added";
$message = array();
$message[]= 'Username : '.trim($user_email).''."\n";
$message = implode($message);
$from='yyyy@gmail.com';
$subject = 'Thank you for successfully creating the account.You can login by using your username';
$headers = 'From: xxxxx@gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(!mail($to, $subject, $message, $headers))
{
$msg = 'Registration is Successful. You can login to start the Online Application.';
$msgclass = 'bg-success';
}
else
{
header("Location: index.php");
exit;
}
}
else
{
$msg = '<div class="alert alert-danger">Password doesn't match!</div>';
$msgclass = 'bg-danger';
}
}
}
?>
电子邮件功能适用于其他数据,但对于注册它不起作用
解决方案
您在 $message[]= 'Username : '.trim($user_email).''."\n"; 中获得 $user_email 变量的位置
你只需使用发布的 $email 地址而不是新变量 $to
推荐阅读
- java - ... 中的构造函数的参数 5 需要找不到类型为“...Mapper”的 bean
- matlab - 在 3d BW 矩阵中查找连通分量 - matlab
- javascript - 如何在 React 的组件中添加外部 javascript 文件?
- c# - 如何使用数组选择控制台颜色?
- gcc - 错误:'redisAsyncContext' 没有命名类型 redisAsyncContext *context;
- octobercms - 如何在octobercms中添加标题和头像
- java - Spring 控制器可以使用相同的端点生成多种内容类型组合吗?
- r - 如何用 R 在同一个图上绘制原始函数、数据点和线性回归曲线?
- liquidsoap - 如何在 Liquidsoap 中一次只加载一首曲目
- c# - C# 中的 DateTime 比较给出了意想不到的结果