繁体   English   中英

在php中注册后无法向用户发送电子邮件

[英]Unable to send email to user after registration in 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&apos;t match!</div>';
                $msgclass = 'bg-danger';
            }
        }
    } 
?>

电子邮件功能对其他数据有效,但对注册无效

您在 $message[]= 'Username: '.trim($user_email).''."\n"; 中获得 $user_email 变量

你只需使用发布的 $email 地址而不是新变量 $to

你让它工作了吗@ntrtrusttesting? 我遇到了类似的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM