Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用一个函数的输出作为另一个函数的输入?_Php_Function_Validation_User Input_Filter Var - Fatal编程技术网

Php 如何使用一个函数的输出作为另一个函数的输入?

Php 如何使用一个函数的输出作为另一个函数的输入?,php,function,validation,user-input,filter-var,Php,Function,Validation,User Input,Filter Var,我有这个功能来检查用户电子邮件在网络表单中的形式正确性,以便使用用户的电子邮件地址向网站管理员发送电子邮件 <?php function verificarEmails($rte) { $_POST['emailRemitente'] = $rte; if (!filter_var($rte, FILTER_VALIDATE_EMAIL)) { echo "<br>Oops! el mail debe ser correcto"; } e

我有这个功能来检查用户电子邮件在网络表单中的形式正确性,以便使用用户的电子邮件地址向网站管理员发送电子邮件

<?php
function verificarEmails($rte) {
    $_POST['emailRemitente'] = $rte;
    if (!filter_var($rte, FILTER_VALIDATE_EMAIL)) {
        echo "<br>Oops! el mail debe ser correcto";
    } else { 
        return $rte;
    }
}
我做错了什么?我很确定我失踪了一头肥硕的大象。此$_POST['EmailTransmitente']是用户输入,问题是VerificationCareMails功能无法工作,它允许使用表单发送格式错误的电子邮件

更新: 完成的第二个功能是:

<?php
function enviarMails($correo) {
    $miEncabezado = "Estimada,<br>";
    $emailRemitente = verificarEmails($_POST['emailRemitente']);
    $nombreRemitente = $_POST['nombreRemitente'];
    $para   = $correo;
    $asunto = 'Urgente';
    $mensaje = $miEncabezado . $GLOBALS['texto'];
    $headers = 'From: '.$nombreRemitente.' '.'<'.$emailRemitente.'>'."\r\n";
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    //mando mail a los usuarios
    $envioUsuarios = mail($para, $asunto, $mensaje, $headers);
    if($envioUsuarios) {
        echo '<br><span class="ok">Mensaje enviado a '.$correo.'</span><br>';
    } else {echo'<br><span class="error">No se mandó mail a '.$correo.'</span><br>';}
}
试试这个

<?php

function enviarMails($correo) {
    if (filter_var($_POST['emailRemitente'], FILTER_VALIDATE_EMAIL)) {
        $miEncabezado = "Estimada,<br>";
        $nombreRemitente = $_POST['nombreRemitente'];
        $para   = $correo;
        $asunto = 'Urgente';
        $mensaje = $miEncabezado . $GLOBALS['texto'];
        $headers = 'From: '.$nombreRemitente.' '.'<'.$_POST['emailRemitente'].'>'."\r\n";
        $headers. = 'MIME-Version: 1.0' . "\r\n";
        $headers. = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

        //mando mail a los usuarios
        if(mail($para, $asunto, $mensaje, $headers)) { 
            echo '<br><span class="ok">Mensaje enviado a '.$correo.'</span><br>'; 
        } else {
            echo'<br><span class="error">No se mandó mail a '.$correo.'</span><br>';
        }
    } else {
        // email not validated
    }
}
具有两个功能:


请共享您的代码。您不需要此行:$\u POST['EmailTransmitente']=$rte;有两种选择。选项1如果电子邮件有效或错误,则返回电子邮件,否则需要检查返回值是否为错误。如果是这样,请打印消息并退出或执行其他操作。选项2您已经做了什么,但退出时停止程序;打印错误信息后。你能分享你的代码吗?我已经用第二个功能更新了帖子,很抱歉第一次没有发布。谢谢你的回复!!!我不太明白的是,为什么不能使用VerificationCareMails$\u POST['EmailTransmitente']…它应该可以运行,但我很惊讶它不能运行。有时可能会出现缓存问题。谢谢您的回复!!!!它确实是这样工作的,但我不明白为什么在尝试分离这两个函数时它不起作用。。。
function verificarEmails($rte) {
    //$_POST['emailRemitente'] = $rte;
    if (!filter_var($rte, FILTER_VALIDATE_EMAIL)) {
        echo "<br>Oops! el mail debe ser correcto";
    } else { 
        return $rte;
    }
}
//another function
function func2($value2) {
     return verificarEmails($value2);

}

echo func2('jack@gmail.com');
<?php

function enviarMails($correo) {
    if (filter_var($_POST['emailRemitente'], FILTER_VALIDATE_EMAIL)) {
        $miEncabezado = "Estimada,<br>";
        $nombreRemitente = $_POST['nombreRemitente'];
        $para   = $correo;
        $asunto = 'Urgente';
        $mensaje = $miEncabezado . $GLOBALS['texto'];
        $headers = 'From: '.$nombreRemitente.' '.'<'.$_POST['emailRemitente'].'>'."\r\n";
        $headers. = 'MIME-Version: 1.0' . "\r\n";
        $headers. = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

        //mando mail a los usuarios
        if(mail($para, $asunto, $mensaje, $headers)) { 
            echo '<br><span class="ok">Mensaje enviado a '.$correo.'</span><br>'; 
        } else {
            echo'<br><span class="error">No se mandó mail a '.$correo.'</span><br>';
        }
    } else {
        // email not validated
    }
}
<?php

function verificarEmails($rte) {
    if (!filter_var($rte, FILTER_VALIDATE_EMAIL)) {
        return false;
    } else { 
        return true;
    }
}

function enviarMails($correo) {
    if (verificarEmails($_POST['emailRemitente']) {
        $miEncabezado = "Estimada,<br>";
        $nombreRemitente = $_POST['nombreRemitente'];
        $para   = $correo;
        $asunto = 'Urgente';
        $mensaje = $miEncabezado . $GLOBALS['texto'];
        $headers = 'From: '.$nombreRemitente.' '.'<'.$_POST['emailRemitente'].'>'."\r\n";
        $headers. = 'MIME-Version: 1.0' . "\r\n";
        $headers. = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

        //mando mail a los usuarios
        if(mail($para, $asunto, $mensaje, $headers)) { 
            echo '<br><span class="ok">Mensaje enviado a '.$correo.'</span><br>'; 
        } else {
            echo'<br><span class="error">No se mandó mail a '.$correo.'</span><br>';
        }
    } else {
        // email not validated
    }
}