0

I am trying to send an confirmation email after user makes an account. The email doesn't send anything. I did test it and the email is not even going to the spam or inbox folder. Am I missing something? Thank you for your help.

$status = "";
    if (isset($_POST["sign_up"])) {
        $first_name     = (isset($_POST['first_name']) ? $_POST['first_name'] : null);
        $last_name      = (isset($_POST['last_name']) ? $_POST['last_name'] : null);
        $username       = (isset($_POST['username']) ? $_POST['username'] : null);
        $password       = (isset($_POST['password']) ? $_POST['password'] : null);
        $email          = (isset($_POST['email']) ? $_POST['email'] : null);
        $phone          = (isset($_POST['phone']) ? $_POST['phone'] : null);

        if ($first_name == "" || $last_name == "" || $username == "" || $password == "" || $email == "" || $phone == "") {
            $status = '<p style="color:#FF0000;">Please fill out all the field';
        } else if (strlen($password) < 6) {
            $status = '<p style="color:#FF0000;">Password must more than 6 characters';
        } else{
            $sql = "INSERT INTO members(
                first_name,
                last_name,
                username,
                password,
                email,
                phone
                ) VALUES (
                '$first_name',
                '$last_name',
                '$username',
                '$password',
                '$email',
                '$phone'
                )";

            $res = mysqli_query($mysqli,$sql) or die(mysqli_error());
            if ($res) {
                $to         = $email;
                $subject    = "Confirmation from Yu Fong to $username";
                $from       = "abc@yahoo.com";
                $message    = "Please click the link below to verify and activate your account. \r\n";
                $message    .= "Testing";
                $header     = "From: " .$from. "\r\n";
                $header     .="Reply-To: ".$from. "\r\n";
                $header     .= "CC: abc@yahoo.com\r\n";
                $header     .= "Return-Path: ".$from. "\r\n";
                $header     .= "MIME-Version: 1.0\r\n";
                $header     .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
                $header     .= "X-Priority: 3\r\n";
                $header     .= "X-Mailer: PHP". phpversion() ."\r\n";


                $sentmail   = mail($to, $subject, $message, $header);

                if ($sentmail == true) {
                    echo $status = '<p style="color:#FF0000;">Congratulations! Your account has been created. An confirmation email has been sent!';
                } else {
                    echo "Eror!";
                }
            }
         }
    }
Frosty
  • 299
  • 5
  • 31
Rick Ng
  • 69
  • 1
  • 1
  • 10
  • 1
    Possible duplicate of [PHP mail form doesn't complete sending e-mail](http://stackoverflow.com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail) – Chris Mar 27 '16 at 00:52
  • 1
    Some mail providers, to deter spam, will reject mail if the sending IP address fails a reverse DNS lookup. Could that be the cause? Check your local mailbox or your SMTP software's logs. – Tyler Crompton Mar 27 '16 at 03:00
  • @TylerCrompton I think DNS could be the cause. I got the email but in the spam folder, how can I prevent this happen? Thank you. – Rick Ng Mar 27 '16 at 03:25

2 Answers2

0

I just tested your email form,it works perfectly,i got the email.

$to         = "Myemail@derp.derp";
$subject    = "Confirmation from Yu Fong to $username";
$from       = "derpington";
$message    = "Please click the link below to verify and activate your account. \r\n";
$message    .= "Testing";
$header     = "From: " .$from. "\r\n";
$header     .="Reply-To: ".$from. "\r\n";
$header     .= "CC: abc@yahoo.com\r\n";
$header     .= "Return-Path: ".$from. "\r\n";
$header     .= "MIME-Version: 1.0\r\n";
$header     .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header     .= "X-Priority: 3\r\n";
$header     .= "X-Mailer: PHP". phpversion() ."\r\n";


$sentmail   = mail($to, $subject, $message, $header);

if ($sentmail == true) {
    echo $status = '<p style="color:#FF0000;">Congratulations! Your account has been created. An confirmation email has been sent!';
} else {
    echo "Eror!";
}

This is just your form,and it works so i am assuming the issue is coming from another place,try changing

if ($res) {

to

if (1+1 == 2) {

just to check if your If statement actually prints true,and go from there.

Frosty
  • 299
  • 5
  • 31
-1

Try changing

if ($sentmail == true) { ... 

to

if ($sentmail) { ...

Or to shorten it a bit try

if(@mail($to, $subject, $message, $headers))

    {
      echo "Mail Sent Successfully";
    }else{
      echo "Mail Not Sent";
    }
Ivan Venediktov
  • 426
  • 2
  • 15
  • 4
    Please don't encourage using the error suppression operator. It causes more headaches than problems it solves. And your first recommendation wouldn't make any difference since it's not a strict comparison. – Tyler Crompton Mar 27 '16 at 03:02
  • Concidering someone upvoted my answer, I guess it solved the problem. – Ivan Venediktov Mar 28 '16 at 02:16
  • And two people downvoted it. I fail to see how your answer fixes the problem at hand anyway. The if conditional change that you suggested makes zero difference in terms of behavior. And the error suppression operator wouldn't fix the problem. If an error is occurring while sending the email and `mail` fails because of it, suppressing the error wouldn't make the email send. – Tyler Crompton Mar 28 '16 at 02:35