REM503 Posted August 9, 2007 Share Posted August 9, 2007 Hello, I am new to PHP and need a little help. I created a simple PHP contact form for my website. When a person submits this form, a copy of it is emailed to me and a copy is emailed to the person submitting the form. How do I eliminate all the PHP junk from appearing in the emails? For example, when I get an email copy of the form submission, the "Comments" section looks something like this: Hi,\r\n\r\nThis is a test.\r\n\r\nThanks,\r\nJohn Doe Is there any way for me to strip all that PHP code so it displays like this in the email instead? Hi, This is a test. Thanks, John Doe Or, if separating the lines is difficult, just have it display like this: Hi, This is a test. Thanks, John Doe Any help would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/64020-eliminating-php-code-from-email-form-results/ Share on other sites More sharing options...
phpknight Posted August 9, 2007 Share Posted August 9, 2007 Create headers for the email and send html instead of text. Use the <br> and <p> tags. Quote Link to comment https://forums.phpfreaks.com/topic/64020-eliminating-php-code-from-email-form-results/#findComment-319180 Share on other sites More sharing options...
JJohnsenDK Posted August 9, 2007 Share Posted August 9, 2007 <?php $headers .= "From: ".$settings['sitename']."\n"; $headers .= "Content-Type: text/html\n"; mail($email, $subject, $content, $headers); ?> Quote Link to comment https://forums.phpfreaks.com/topic/64020-eliminating-php-code-from-email-form-results/#findComment-319182 Share on other sites More sharing options...
phpknight Posted August 9, 2007 Share Posted August 9, 2007 Right. In fact, I find myself sending that so much, you are better off making your own mail function that sends all email. That way you do not have to worry about headers at all. Plus, you can send a copy of all email back to yourself in case somebody is spamming through your forms or whatever. The prototype might be: sendMyEmail ($toAddress, $subject, $body, $name=YOUR_SITE, $fromAddress = YOUR_EMAIL) { function here } That way, you can send email normally if you want, and you can optionally change the name of the sender ($name), and from address. The constants could be used for default and changed whenever you want. Inside this function, the headers and html/body closing tags will be taken care of, and all you send is the html formatted email. If you change headers a lot, you could add another variable, too, for that part. Quote Link to comment https://forums.phpfreaks.com/topic/64020-eliminating-php-code-from-email-form-results/#findComment-319206 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.