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

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -