使用php codeigniter创建一个电子邮件检查器

请帮我创建一个允许用户提交有效电子邮件的表单。</ p>

当有人尝试输入电子邮件ID时,应在提交给数据库之前对其进行验证。 垃圾邮件ID的一些示例是 test@abc.com </ code>, 123@xyz.com </ code>等。</ p>

如果是用户 尝试输入上面示例中提到的电子邮件ID,应该验证它是否是有效的电子邮件ID,并检查具有电子邮件ID的用户是否已经存在?</ p>

请帮我在php codeigniter中构建代码。</ p>
</ div>

展开原文

原文

Please help me in creating a form which allows a user to submit valid email.

When someone try to enter an email id, it should be validated before submitted to data base. Some of the examples for junk email ids are test@abc.com, 123@xyz.com etc.

If an user try to enter an email id as mentioned in the above example, it should be verified whether it is a valid email id or not and also check if the user with the email id already exists?

Kindly help me building a code in php codeigniter.

dpwdldgn43486
dpwdldgn43486 你从我的回答中得到了一些想法吗?
接近 6 年之前 回复
dpd3982
dpd3982 如果你想要你的代码我们将如何知道你正在尝试某些事情,请向我们展示你的努力
接近 6 年之前 回复
dqsong2010
dqsong2010 您的意思是有效的语法,或属于某人的有效工作电子邮件?前者可通过CodeIgniter的FormValidator类实现-查找它,它可以验证电子邮件。后者是不可能的。
接近 6 年之前 回复

3个回答



您还可以使用dns验证电子邮件域。</ p>

  public function check_domain(  $ email)
{
if if(!(bool)checkdnsrr(preg_replace('/ ^ [^ @] ++ @ /','',$ email),'MX'))
{

返回FALSE ;
}

返回TRUE;
}
</ code> </ pre>
</ div>

展开原文

原文

You can also validate the email domain using dns.

public function check_domain($email)
{
    if( ! (bool) checkdnsrr(preg_replace('/^[^@]++@/', '', $email), 'MX'))
    {
        return FALSE;
    }

    return TRUE;
}



CI中有一个内置功能可以为您处理。 它位于表单验证库中。</ p>

请参阅: https://ellislab.com/codeigniter/user-guide/libraries/form_validation.html </ p>

 <代码> $这 - &GT; form_validation-&GT; set_rules(  'email','Email','required | valid_email | is_unique [users.email]'); 
</ code> </ pre>

请注意已为您提供的valid_email规则。 </ p>

希望有所帮助。</ p>
</ div>

展开原文

原文

There is a build-in functionality in CI handling this for you. It is in the form validation library.

See: https://ellislab.com/codeigniter/user-guide/libraries/form_validation.html

$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[users.email]');

note the valid_email rule which is already provided for you.

Hope it helps.

dongnuo3749
dongnuo3749 如果您需要有效的工作电子邮件(现有电子邮件),则需要用户在将其存储在数据库中之前确认其电子邮件。 我认为没有第三方解决方案,因为它需要第三方提供商跟踪每个现有的电子邮件(这是不可能的)。 因此,可能会发送一封确认电子邮件,其中包含指向您的控制器的链接(urdomain.com/contr/meth),其方法是确认时将电子邮件放入数据库/激活用户或您想要的内容。
接近 6 年之前 回复
doutou6803
doutou6803 嗨,其实我想要的是有效的工作电子邮件! 是否可以通过第三方API? 请澄清一下,谢谢。
接近 6 年之前 回复
douzhaolu4839
douzhaolu4839 哦,为了检查电子邮件是否确实存在于数据库中,您可以使用回调方法。 请参阅:ellislab.com/codeigniter/user-guide/libraries/...
接近 6 年之前 回复

First of all i would like to give you a function for checking email address domains either they exists or not and after that i will try to figure out verification process that either user has already been registered from before or not and reference link to checkdnsrr().

I have divided my answer into three parts

  1. Verifying the Domain either it do exist or not
  2. Client side verification can be done via jquery or html5
  3. Unique Email address to be registered

Part 1


Try this function with several different domain names. This code work for me and i hope wi

function validate_email($email="zazikhan1@wowowowowowowowoowoowowowo.com"){

   $exp = "^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";

   if(stristr($exp,$email)){

      if(checkdnsrr(array_pop(explode("@",$email)),"MX")){
        echo 'good to go';
      }else{
        echo 'domain cant be verified';
      }

   }else{

  echo 'sorry regular expression does not match';

   }    
}

Part 2


If you want to do that by jquery so visit jquery rain and select the plugin what ever you like but if you like to that in html5 just simply

<input type="email" id="email" name="email" required>

In html5 email will automatically validate either user have put the email by seeing @ sign in it .

And required tag will simply see either user have full fill the email field before proceeding further.


Part 3


Here is the code for to don't register those email which have registered already.

 function subscriber()
   {
       $subscriber=$this->input->post('subscriber');
       $query=$this->cartmodel->get_record('subscriber',array('email'=>$subscriber));
       if($query)
       {
          $this->session->set_flashdata('error', '<script type="text/javascript">alert("you are already registered with us")</script>'); 
          redirect('views');
       }
       else
       {
        $data=array('email'=>$this->input->post('subscriber'));
        $this->cartmodel->insert_data('subscriber',$data);
        $this->session->set_flashdata('error', '<script type="text/javascript">alert("you have sucessfully subscribed with us")</script>');
        redirect('views');
       }
   }
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问