/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$mailFrom = "ValidMailbox@validdomain"; $mailTo = "ValidToAddress"; $mailSubject = "Useful Subject: Here's my subject"; $mailSignature = "\n\n-- \n"; $mailSignature .= "Your friendly Neighborhood web application.\n"; $mailSignature .= "For help and other information, see http://yourwebapp/help\n"; $mailBody = "blahblahblah\n"; $mailBody .= $mailSignature; $mailHeader = "From: $mailFrom "; $mailHeader .= "Reply-To: $mailFrom "; $mailHeader .= "X-Mailer: ".MYSITE." "; $mailHeader .= "X-Sender-IP: {$_SERVER['REMOTE_ADDR']} "; $mailHeader .= "Bcc: ".MONITORADDRESS." "; // Test with this additional headers: $mailHeader .= 'MIME-Version: 1.0' . " " $mailHeader .= 'Content-Type: text/html; charset="iso-8859-1"'." "; $mailHeader .= "Content-Transfer-Encoding: 8bit\n"; $mailParams = "-f$mailFrom"; //A Bonus Snippet $mysite = whatsMySite(); function whatsMySite() { // protocol $mysite = "https://"; } else { $mysite = "http://"; } // host $mysite .= $_SERVER['HTTP_HOST']; // path if("/" != $path) { $mysite .= $path; } return($mysite); } // Filter Methods // Filter After Submit // clean the data prior to actually processing it. A function like the one below can be use for this purpose. // will replace the newlines and carriage returns // Watch out for deprecated method preg_replace function heal($str) { '/(\r+)/i', '/(\t+)/i', '/(%0A+)/i', '/(%0D+)/i', '/(%08+)/i', '/(%09+)/i', '/(BCC:+)/i', '/(CC:+)/i', '/(TO:+)/i' ); return $str; } function safe( $name ) { return( str_ireplace(array( "\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:" ), "", $name ) ); } // Validation function which returns true if it finds newlines or carriage returns in the passed string function isInjected($str) { '(\r+)', '(\t+)', '(%0A+)', '(%0D+)', '(%08+)', '(%09+)' ); $inject = "/$inject/i"; return true; } else { return false; } } Another method for filtering after the submit might look like the following. Be sure to change $_POST to $_GET if you are using that method. foreach( $_POST as $value ){ } }
URL: http://collaborate.extension.org/wiki/Best_Practices_Using_the_PHP_mail_Function