M
M
Margo19642015-12-08 03:23:26
PHP
Margo1964, 2015-12-08 03:23:26

How to make a universal PHP script that will collect all form fields and send them to E-mail?

The script should send to the mail absolutely any number of fields with completely different names. A universal script that will send any form to the mail. As I understand it, you need to take all the name variables from the request, make an array and send it to the mail.
I can't figure out how to write such code.
For example, how to do it on formspree.io - there the input parameter is only E-mail, the rest of the fields are taken from the form of any complexity.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
entermix, 2015-12-08
@Margo1964

<?

$text = '';

if (count($_GET) > 0) {
    foreach ($_GET as $key => $value) {
        $text .= 'key: ' . $key . ', value: ' . $value . "\r\n";
    }
}

if (count($_POST) > 0) {
    foreach ($_POST as $key => $value) {
        $text .= 'key: ' . $key . ', value: ' . $value . "\r\n";
    }
}

// отправка почты

?>

You can also use 1 variable $_REQUEST (instead of $_POST and $_GET separately), but it also includes the contents of cookies

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question