How should I check (screen) user-entered $ email and $ message before sending it with the mail () function?
$headers = 'Content-Type: text/plain; charset=utf-8' . "\r\n" . 'From: ' . $email; mail('myemail@gmail.com', 'Subject', $message, $headers); How should I check (screen) user-entered $ email and $ message before sending it with the mail () function?
$headers = 'Content-Type: text/plain; charset=utf-8' . "\r\n" . 'From: ' . $email; mail('myemail@gmail.com', 'Subject', $message, $headers); Alternatively, you can use this approach.
function _filterEmail($email) { $rule = array("\r" => '', "\n" => '', "\t" => '', '"' => '', ',' => '', '<' => '', '>' => '', ); return strtr($email, $rule); } function _filterOther($data) { $rule = array("\r" => '', "\n" => '', "\t" => '', ); return strtr($data, $rule); } $email = _filterEmail($email); $message = _filterOther($message); mail(...); Built-in function is easy to filter soap :
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
The body, as far as I understand this example, is permissible not to filter.
Source: https://ru.stackoverflow.com/questions/522563/
All Articles