简体   繁体   English

如何使我的电子邮件代码可以使用PHP?

[英]How can I make my email code work 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: 所以总结一下,当没有这样的输入时,所有5个都在工作:

  • 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? 我该如何修正我的代码,使所有3个代码都被1个一掉?

To make your own callback you can't just pass the constant MAIL_NAME_ERROR . 要进行自己的回调,您不能仅传递常量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 . 请参阅http://php.net/manual/zh/function.filter-var.php中options部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM