A really simple PHP problem

Soldato
Joined
20 Oct 2002
Posts
19,035
Location
London
Right. Just a question of syntax, really. I've modified a script that somebody made for me years ago -- to send mail from a form. I'm trying to modify it to send HTML email and am fairly successful. But if I use the below code, I only get my first header. If I remove the ; then I get an error. :confused:

Relevant code:

PHP:
$message = '<html>
<head>
<title>Gobo Web Form</title>
</head>
	<body>
	<h2>Name:</h2>
	<p>'.stripHeaders(trim($_POST['name']));'</p>
	<h2>Company:</h2>
	<p>'.stripHeaders(trim($_POST['company']));'</p>
	</body>
</html>';
Stripheaders just does this:
PHP:
function stripHeaders($string) {
	return preg_replace('#(content-type:|to:|cc:|bcc:)#i', '', $string);
}

Please don't hurt me. I really don't know any PHP nor am I much of a programmer!! Many thanks in advance! :)
 
Beautiful thanks very much. PHP is fun :)

Btw, it's basically a form for visitors to fill in -- that sends to a specified addres (owner of the website). Is there any need to put a plaintext equivalent message? I mean, it's only ever going to his address so surely there's no need?
 
I can't see why if it always go to the same address. With the form send if I would look at adding a recaptcha as well just to stop anything nasty :)
You mean as in this: http://recaptcha.net ?

I have these functions to stop any nasty input:

PHP:
function stripLineBreaks($string) {
	return preg_replace('#(%0A|%0D|\\n+|\\r+)#i', '', $string);
}
function stripHeaders($string) {
	return preg_replace('#(content-type:|to:|cc:|bcc:)#i', '', $string);
}
// This function does a basic validation of an email address
function isValidEmail($string) {
	return preg_match('#^\w[-.\w]*@([-a-z0-9]+\.)+[a-z]{2,4}$#i', $string);
}

// Check if they user has sent a mail in the last sixty seconds
$withinTimeLimit = $_SESSION['lastMailed'] + 60 < time();
 
Back
Top Bottom