0

I need users to send an invitation link to their friends. it works fine before but now I don't know what happened is not working please help. The current PHP version is 8.0 the code works fine but the email will not deliver

<?php
session_start();
require("../include/admin_helper.php");
// global $con;

$invite = mysqli_query($con, "SELECT id, auser FROM admin_v WHERE id = $admin_id ");
$get_inviter = mysqli_fetch_assoc($invite);
$inviter_id = $get_inviter ['id'];
$inviter_user = $get_inviter ['auser'];


if (isset($_POST["signup"])) {
  $full_name = mysqli_real_escape_string($con, $_POST["signup_full_name"]);
  $email = mysqli_real_escape_string($con, $_POST["signup_email"]);
//   $password = mysqli_real_escape_string($con, md5($_POST["signup_password"]));
//   $cpassword = mysqli_real_escape_string($con, md5($_POST["signup_cpassword"]));
  $token = md5(rand());
  $check_email = mysqli_num_rows(mysqli_query($con, "SELECT email FROM members WHERE email='$email'"));
  
   if ($check_email > 0) {
     echo "<script>alert('Your are already sent the invitation');</script>";
   } else {
    $sql = "INSERT INTO members (full_name, email, token, status) VALUES ('$full_name', '$email', '$token', '0')";
    $result = mysqli_query($con, $sql);
    if ($result) {
      $_POST["signup_full_name"] = "";
      $_POST["signup_email"] = "";
      $subject = "Invitation";
      
      $to = $email;

      $message = "
      <html>
      <head>
      <title>{$subject}</title>
      </head>
      <body>
      <p><strong>Welcome {$full_name},</strong></p>
      <p>This is Membership inivitaion! Verify your link to access our website. Click below link to verify your email.</p>
      <p><a href='https://elom.com/login/invite.php?token={$token}&i={$inviter_id}&u={$inviter_user}'>Accept invitation</a></p>
      </body>
      </html>
      ";
      
      $subject="Email invitation - elom.com";
      $body = $message;
      $from_address="invite@".$_SERVER['SERVER_NAME'];
      $from_name="Elom";
      $headers = "MIME-Version: 1.0\r\n"
      ."Content-Type: text/html; charset=utf-8\r\n"
      ."Content-Transfer-Encoding: 8bit\r\n"
      ."From: =?UTF-8?B?". base64_encode($from_name) ."?=<$from_address>\r\n"
      ."X-Mailer: PHP/".phpversion();
       mail($to, $subject, $body, $headers, "-fwebmaster@{$_SERVER['SERVER_NAME']}");
       echo "<script>alert('We have sent a invitation link to your friend email - {$email}.');</script>";
    } else {
      echo "<script>alert('Friend invitation failed.');</script>";
    }
  }
}
//  echo $inviter;
//  echo "hello";
?>
<form method="post" action="">

    <label class="col-lg-2 col-form-label">Full Name</label>
    <div class="col-lg-9">
        <input type="text" class="form-control" name="signup_full_name" required
            value="<?php echo $_POST["signup_full_name"]; ?>"
            placeholder="Full Name">
    </div>

    <label class="col-lg-2 col-form-label">Email</label>
    <div class="col-lg-9">
        <input type="email" class="form-control" name="signup_email" required
            value="<?php echo $_POST["signup_email"]; ?>" placeholder="Email">
    </div>

    <br>
    <div class="col-lg-9">
        <button class="btn btn-primary" name="signup"
            style="margin-left:5px;">invite</button>
    </div>

</form>

I need users to send an invitation link to their friends. it works fine before but now I don't know what happened is not working please help. The current PHP version is 8.0 the code works fine but the email will not deliver

0 Answers0