2016-03-27 15 views
0

ユーザーがアカウントを作成した後に確認メールを送信しようとしています。電子メールは何も送信しません。私はそれを試して、電子メールは迷惑メールや受信トレイのフォルダにも行きません。何か不足していますか?ご協力ありがとうございました。PHPでメールを送信できません

$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  = "[email protected]"; 
       $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: [email protected]\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!"; 
       } 
      } 
     } 
    } 
+1

が重複する可能性を試してみてください、それを短縮するに

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

を変更してみてください[PHPメールフォームは、電子メールの送信を完了していません] (http://stackoverflow.com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail) – Chris

+1

一部のメールプロバイダは、スパムを阻止するために、送信IPアドレスが逆DNSルックアップに失敗した場合は、メールを拒否します。それが原因だろうか?ローカルメールボックスまたはSMTPソフトウェアのログを確認してください。 –

+0

@TylerCrompton私はDNSが原因だと思う。私は電子メールを受け取りましたが、迷惑メールフォルダには、どうしてこれが起こらないようにすることができますか?ありがとうございました。 –

答えて

0

あなたのメールフォームをテストしたところ、完全に動作します。メールが届きました。

$to   = "[email protected]"; 
$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: [email protected]\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!"; 
} 

これは自分のフォームであり、それは私があなたの場合は、単にチェックする

if (1+1 == 2) { 

if ($res) { 

を変更してみてください、問題は別のところから来ていると仮定しています動作しますif文が実際にtrueを出力し、そこから移動します。

-1

if ($sentmail) { ... 

またはビットの

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

    { 
     echo "Mail Sent Successfully"; 
    }else{ 
     echo "Mail Not Sent"; 
    } 
+4

エラー抑制演算子の使用はお勧めしません。それは、それが解決する問題よりも頭痛を引き起こします。最初の勧告は厳密な比較ではないので何の違いもありません。 –

+0

誰かが私の答えをupvoted concidering、私はそれが問題を解決したと思います。 –

+0

そして2人がそれを落とした。私はあなたの答えがどうにか問題を解決しているかを見失う。あなたが提案したif条件付き変更は、動作の点で違いをゼロにします。エラー抑制演算子は問題を解決しません。電子メールの送信中にエラーが発生し、そのために 'mail'が失敗した場合、エラーを抑制しても電子メールは送信されません。 –

関連する問題