php mail function within function - how secure is this? -
i've been reading php mail injection , possible security risks. i've decided control of via function , pass in email , contact message.
just wondered how secure , prevent sort of injection?
//contact form function sendcontactform($contactemail, $contactmessage) { $to = "mysite@mysite.com"; $from = "mysite@mysite.com"; $replyto = filter_var($contactemail, filter_validate_email); $subject = "contact form email"; $message = $contactmessage; $headers = "from: " . $from . "\r\n"; $headers = "reply-to:" . $replyto . "\r\n"; $headers .= "content-type: text/html\r\n"; $success = mail($to, $subject, $message, $headers); }
it's not secure: user inject code in $contactmessage.
my suggestion use htmlentities(), converts characters in entities (where possible).
you can use strip_tags(), returns string without html tags.
Comments
Post a Comment