我如何使我的电子邮件代码工作PHP? [英] How can I make my email code work PHP?

查看:108
本文介绍了我如何使我的电子邮件代码工作PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个代码假设在输入的电子邮件表单上没有输入输入时假设添加一个错误消息,并且假设在最后输入代码时删除错误消息。我有2个使用以下代码:

  //生成唯一代码
函数getUniqueCode($ length =)
{
$ code = md5(uniqid(rand(),true));
if($ length!=)return substr($ code,0,$ length);
else return $ code;
}

//生成激活密钥
函数generateActivationToken($ gen = null)
{
do
{
$ gen = md5(uniqid(mt_rand(),false));
}
while(validateActivationToken($ gen));
return $ gen;
}

此代码:

  //检查电子邮件是否有效
函数isValidEmail($ email)
{
if(filter_var($ email,FILTER_VALIDATE_EMAIL)){
返回true;
}
else {
return false;
}
}

我已经制作了自己的代码,将错误消息当电子邮件表单上没有输入,但是当我在电子邮件表单中输入正确的内容时,它不会将错误消息从错误消息框中删除。以下是代码:

  //检查名称是否有效
函数isValidName($ name)
{
if(filter_var($ name,MAIL_NAME_ERROR)){
return true;
}
else {
return false;
}
}

所以总结一下,当没有输入如下:



  • 请输入您的全名

  • 请输入有效的电子邮件地址

  • 请输入您的电话号码

  • 请输入您的密码

  • 安全问题失败


但是,当我输入我的电子邮件地址和安全代码时,只有我的安全和电子邮件正常工作:



  • 请输入您的全名

  • 请输入您的电话号码

  • 请输入您的密码


电话和密码不正常,他们只能通过显示代码进行工作,但是在输入正确的信息时不会删除代码。



如何修复我的代码所有3将会消失1 1?

解决方案

为了使自己的回调不能通过常量 MAIL_NAME_ERROR 。如果你想传递你自己的功能,你必须这样做:

  function mail_name_error(){
//在这里做你的东西
}
函数isValidName($ name){
if(filter_var($ name,FILTER_CALLBACK,array('options'=>'mail_name_error'))){
返回true;
}
else {
return false;
}
}

请参阅 code>部分在 http://php.net/manual/en/ function.filter-var.php


Hey this code is suppose to add an error message when an input was not typed on the email form and its suppose to remove the error message when you finally input the code. I have 2 of them working with the following code:

//Generate a unique code
function getUniqueCode($length = "")
{   
$code = md5(uniqid(rand(), true));
if ($length != "") return substr($code, 0, $length);
else return $code;
} 

//Generate an activation key
function generateActivationToken($gen = null)
{
do
{
    $gen = md5(uniqid(mt_rand(), false));
}
while(validateActivationToken($gen));
return $gen;
}

and this code:

//Checks if an email is valid
function isValidEmail($email)
{
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    return true;
}
else {
    return false;
}
}

I have made my own code which puts the error messages when there are no inputs on the email form but when I input something right on the email form it does not take the error messages out of the error message box. Here is the code:

//Checks if a name is valid
function isValidName($name)
{
if (filter_var($name, MAIL_NAME_ERROR)) {
    return true;
}
else {
    return false;
}
}

So to summarize all 5 are working when there is no input like this:

  • Please enter your full name
  • Please enter a valid email address
  • Please enter your telephone number
  • Please enter your password
  • Failed security question

But only my security and email are working when I input my email address and security code like this:

  • Please enter your full name
  • Please enter your telephone number
  • Please enter your password

The name, telephone and password are not working right they only work by showing the code but they do not remove the code when I input the right information.

How can I fix my code so that all 3 will go away 1 by 1?

解决方案

To make your own callback you can't just pass the constant MAIL_NAME_ERROR. If you want to pass your own function you have to do something like:

function mail_name_error(){
  //do your thing here
}
function isValidName($name){
  if(filter_var($name, FILTER_CALLBACK, array('options' => 'mail_name_error'))){
    return true;
  }
  else {
    return false;
  }
}

See the options section at http://php.net/manual/en/function.filter-var.php .

这篇关于我如何使我的电子邮件代码工作PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆