Jump to content

Form Snag


ScottAllenNet

Recommended Posts

Hi Guys,

 

PHP has never been my fortay and I have hit a real snag.

 

Please find below code for a simple PHP contact form. However, in the subject line of the email sent to me I would like it to show:

 

Contact Form: $subject  - ($subject is what is currently displayed).

 

I know this is a simple fix however I have been messing about for hours and can't seem to get it right.

 

Any help would be greatly appreciated.

 

Best,

 

Scott.

 





<?php

define("WEBMASTER_EMAIL", 'contact@pearceresourcing.com');

error_reporting (E_ALL ^ E_NOTICE);

//////////////////////////////////////////////////////

function ValidateEmail($email)
{
	$regex = '/([a-z0-9_.-]+)'. # name
	'@'. # at
	'([a-z0-9.-]+){2,255}'. # domain & possibly subdomains
	'.'. # period
	'([a-z]+){2,10}/i'; # domain extension 

	if($email == '') 
		return false;
	else
		$eregi = preg_replace($regex, '', $email);
	return empty($eregi) ? true : false;
}

//////////////////////////////////////////////////////

$post = (!empty($_POST)) ? true : false;

if($post)
{
	$name 	 = stripslashes($_POST['name']);
	$email 	 = trim($_POST['email']);
	$subject = trim($_POST['subject']);
	$message = stripslashes($_POST['message']);

	$error = '';

	// Check name
	if(!$name)
		$error .= 'Name required! ';

	// Check email
	if(!$email)
		$error .= 'E-mail required! ';

	if($email && !ValidateEmail($email))
		$error .= 'E-mail address is not valid! ';

	// Check message
	if(!$message)
		$error .= "Please enter your message!";

	if(!$error)
	{
		$mail = mail(WEBMASTER_EMAIL, $subject, $message,
			 "From: ".$name." <".$email.">\r\n"
			."Reply-To: ".$email."\r\n"
			."X-Mailer: PHP/" . phpversion());

		if($mail)
			echo 'OK';
	}
	else
		echo '<div class="errormsg">'.$error.'</div>';
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.