Quantcast
Channel: Active questions tagged return-value - Stack Overflow
Viewing all articles
Browse latest Browse all 210

How to call a function and return data from a function to the global scope?

$
0
0

I created an HTML form that, on submit, opens submit_form.php. Inside, I process the data entered into the form and send a confirmation email. I wrote a function for the mail-sending-process.
Inside the .php file, I have PHP, as well as HTML code. The important parts of the file look like this:

<?php    $success = "undefined";    /* ... */    function send_mail($to, $from, $fromName, $subject, $message) {        /* headers, etc. */        if (mail($to, $subject, "", $header)) {            $success = "true";        } else {            $success = "false";        }    }?><html><body>        success? <?php echo $success; ?></body</html>

Now, when loading the HTML on the success site (HTML code below the .php script, in the same file), I put this code to verify whether the email was sent successfully:

success? <?php echo $success; ?>

...which presents the following output: success? undefined


Viewing all articles
Browse latest Browse all 210

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>