开发者

How to validate multiple email addresses using PHP and output valid ones

I want to write a script that takes about 5 email addresses and then check if they are valid and if they are then send a message to each email address. I previously wrote this but got stuck along the way because the code runs when all emails were valid. 开发者_开发知识库How do i individualize the emails for checking and making sure even if one of the emails is invalid the code will display the rest of the valid ones.

<form method="post" action="validate_emails.php">
<p>Enter emails and separate them with a comma.</p>
<textarea name="emails" cols="50" rows="10">

</textarea>

<p><input name="send" type="submit" value="submit"></p>
</form>
<?php

if(isset($_POST['send'])) {
    $fes = preg_split('[,\r\n]', $_POST['emails']);


    foreach ( $fes as $key => $email ) 
    {     

      if(filter_var($email, FILTER_VALIDATE_EMAIL)){
            echo $fes[key];

                    //mailing to code not entered.

      }


    } 

}

?>


foreach ( $fes as $key => $email ) 
    {     

      if(filter_var($email, FILTER_VALIDATE_EMAIL) == false){
            // email is invalid, do what you want
           continue;
      }

     // now email is valid 
     // code for sending email
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜