The Web Squeeze: Php For Email Form - The Web Squeeze

Jump to content

Forum

PHP

This PHP Support Forum will help you troubleshoot php, learn best php coding practices and anything else you care to know about creating dynamic websites using PHP, the most popular server-sided language in the net. Our enthusiastic PHP experts can help you take your website from static to dynamic in no time.
Digg Del.ico.us Slashdot Technorati furl Reddit Facebook Fark Google Magnolia Wink Yahoo Netscape
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Php For Email Form

#1 User is offline   xkatx21x Icon

  • New Squeeze
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 15-February 08
  • Gender:Female
  • Location:Auckland, NZ

  Posted 17 February 2008 - 09:26 PM

Does anyone know where I can find a script wizard for a PHP email form? I have the HTML form ready but don't know the first thing about PHP :girl_impossible: . My partner has just placed a advert in the local papers for his business so I would like the "quote form" ready in time for the advert as hopefully there should be an increase in traffic.

The URL for the form is www.solidmasonry.co.nz/quote.html

If anyone has a few spare minutes to look at it and maybe help me out I would be willing to pay a few dollars if someone was to write the script for me :flirt:

Thank you in advance for any help or advice received.
0

#2 User is offline   Rakuli Icon

  • Community Director
  • Icon
  • Group: Community Director
  • Posts: 1,378
  • Joined: 13-February 08
  • Gender:Male
  • Location:Catching the squeezed drips downunder.

Posted 17 February 2008 - 09:46 PM

Well I could code the script for you in a relatively short time -- what is it you want it to do? Just send the results via email or store to a database or give an online quote?

Alternatively, if you just want the results sent to an email address, there are services out there that provide this. You point the action of your form at their script and it will process and mail to you.

#3 User is offline   xkatx21x Icon

  • New Squeeze
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 15-February 08
  • Gender:Female
  • Location:Auckland, NZ

Posted 17 February 2008 - 10:01 PM

View PostRakuli, on Feb 17 2008, 10:46 PM, said:

Well I could code the script for you in a relatively short time -- what is it you want it to do? Just send the results via email or store to a database or give an online quote?

Alternatively, if you just want the results sent to an email address, there are services out there that provide this. You point the action of your form at their script and it will process and mail to you.


Hi yes I just want the results emailed to me. I'd rather have the script though rather than using an outside source. If you could do that it would be fantastic. :pleasantry:
0

#4 User is offline   c010depunkk Icon

  • Squeeze Machine
  • Icon
  • Group: Advisors
  • Posts: 501
  • Joined: 14-February 08
  • Gender:Male
  • Location:Düsseldorf, Germany

Posted 18 February 2008 - 02:02 AM

hmm... maybe we should make a sticky. This is probably the first of many similar questions... :D
an umcomfortably attractive blend of sort of perverted but suprisingly sweet.
i.met.janvt.com
0

#5 User is offline   Rakuli Icon

  • Community Director
  • Icon
  • Group: Community Director
  • Posts: 1,378
  • Joined: 13-February 08
  • Gender:Male
  • Location:Catching the squeezed drips downunder.

Posted 18 February 2008 - 02:38 AM

Here you go I have created an email form for you.

You need to make a few changes to your form in order for it to work -- the form should be changed to look like this. It is customised for your form but is easily altered for any form due to the simple array setup at the top.

<form method="post" action="the url to the script here" enctype="multipart/form-data">
<select name="title">
<option value="mr">Mr</option>
<option value="mrs">Mrs</option>
<option value="miss">Miss</option>
<option value="ms">Ms</option>
<option value="other">Other</option>
</select><br><br>
First name: <br>
<input type="text" name="firstname">
<br><br>
Last name:<br> 
<input type="text" name="lastname">
<br><br>
Email address:<br>
<input type="text" name="email">
<br><br>
Phone number:<br>
<input type="text" name="phone">
<br><br>
What suburb are you in?
<br>
<input name="suburb" type="text" />
<br><br>
What kind of work would you like to request a quote for?
<br>
<select name="work">
<option value="brick">Brick Work</option>
<option value="block">Block Work</option>
<option value="paving">Paving</option>
<option value="concrete">Concrete Pumping</option>
<option value="grout">Grout Pumping</option>
<option value="other">Other</option>
</select>
<br><br>
Please give an idea of the work to be done?
<textarea name="work2bdone" rows="15" cols="40">
  </textarea>
<br><br>
What is the best day for us to contact you ?<br>
(Tick all that apply)<br><br>

<input type="checkbox" name="day[]" value="Monday">
Monday<br>
<input type="checkbox" name="day[]" value="Tuesday">
Tuesday<br>
<input type="checkbox" name="day[]" value="Wednesday">
Wednesday<br>
<input type="checkbox" name="day[]" value="Thursday">
Thursday<br>
<input type="checkbox" name="day[]" value="Friday">
Friday<br>
<input type="checkbox" name="day[]" value="Saturday">
Saturday<br>
<input type="checkbox" name="day[]" value="Sunday">
Sunday
<br><br>
What time is best for us to contact you?<br>
(Tick all that apply)<br><br>
<input type="checkbox" name="time[]" value="8-12">
8am-12am<br>
<input type="checkbox" name="time[]" value="12-5">
12am-5pm<br>
<input type="checkbox" name="time[]" value="5-9">
5pm-9pm<br>
<input type="checkbox" name="time[]" value="Any">
Anytime
<br><br>
Where did you hear about us?<br>
<select name="find">
<option value="google">Google</option>
<option value="friend">Through a friend</option>
<option value="busref">Through another business</option>
<option value="locpaper">Local newspaper</option>
<option value="natpaper">National newspaper</option>
<option value="buscard">Our business card</option>
<option value="car_graphic">Vehicle advertising</option>
<option value="other">Other</option>
</select>
<br><br>
  <input type="submit"  name="submit" value="Request Quote">
</form>



The PHP code is below -- I have also attached the whole script to this message.

<?php

$returnURL = 'http://www.example.com'; 				// The url to send the user back to if something went wrong
$successURL = 'http://www.example.com/success.html';// The url to send the user to if all goes well

$Temail 	= 'rakuli@oce.com';// Change it to anything you like -- is where the email will be sent to
$TemailBcc  = 'random2@example.com'; // If you want to copy anyone in on all emails sent from the form, add them here separated by commas
$Semail		= '"Solid Masonry - Online Contact Form" <%s>';

// If we didn't receive the correct input from the submit button, we'll send them away straight awa

if (isset($_POST['submit']))
{

	//header ('Location: ' . $returnURL);
	//exit();


// Set up an array of the elements to check and place in our message
// if you want the value to be mandatory, change the false to true -- don't change 4=>true though

$formInputs = array('title' 		=> array('Title', true, array('mr', 'mrs', 'miss', 'ms', 'other')),
					'firstname' 	=> array('First Name', true),
					'lastname'		=> array('Last Name', true),
					'email'			=> array('Email Address', true, 3 => 'check_email'),
					'phone'			=> array('Phone Number', false, 3 => 'ctype_digit'),
					'suburb'		=> array('Suburb', false),
					'work'			=> array('Work Type Request', false, array('brick', 'block', 'paving', 'concrete', 'grout', 'other')),
					'work2bdone'	=> array('Work To Be Performed', false),
					'day'			=> array('Best Day For Contact', false, array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'), 4 => true),
					'time'			=> array('Best Time For Contact', false, array('8-12', '12-5', '5-9', 'Any'), 4 => true),
					'find'			=> array('Where You Heard About Us', false, array('google', 'friend', 'busref', 'locpaper', 'natpaper', 'buscard', 'car_graphic', 'other'))
					);


// now loop throught that new array and sort everything out

$errors 		= array(); // Here is our errors list -- we will fill it as required
$errorMsg		= 'Please check that you entered <strong>%s</strong> correctly';

$messageArray	= array(); // Will hold the list of values to send out in the email
foreach ($formInputs as $pk => $pa)
{
	if (!isset($_POST[$pk]) && $pa[1] === true)
	{echo 'die ' . $_POST[$pk];
		$errors[] = sprintf($errorMsg, $pa[0]);
		continue;
	}
	


/***** Form inputs that have multiple available selections *****/
	if ($pa[4] === true && is_array($_POST[$pk])) {
	
		$msg = '';
		foreach($_POST[$pk] as $val)
		{
			$msg .= in_array($val, $pa[2]) ? "\t\t" . htmlentities($val) . "<br />\n" : '';
		}
		
		if (!empty($msg))
			$messageArray[] = '<strong>' . $pa[0] . "</strong> : <br />\n\n<br />" . $msg;
		else if ($pa[1] === true) 
			$errors[] = sprintf($errorMsg, $pa[0]);
		
		continue;
	} else if ($pa[1] === true && $pa[4] === true) {
		$errors[] = sprintf($errorMsg, $pa[0]);
		continue;
	}

/***** Form inputs that have a list of options to select from ******/

	if (isset($pa[2]))
	{

		if (in_array($_POST[$pk], $pa[2]))
		{
			$messageArray[] = '<strong>' . $pa[0] . '</strong> : ' . htmlentities($_POST[$pk]);
		} else if ($pa[1] === true) 
			$errors[] = sprintf($errorMsg, $pa[0]);
		
		continue;
	}
	$_POST[$pk] = trim($_POST[$pk]);

	if (empty($_POST[$pk]) && $pa[1] === true)
	{
		$errors[] = sprintf($errorMsg, $pa[0]);
		continue;
	} else if (empty($_POST[$pk]))
		continue;

/**** Form inputs that require some sort of validation (phone numbers/email) ****/

	if (isset($pa[3]))
	{
		if ($pa[3]($_POST[$pk]))
			$messageArray[] = '<strong>' . $pa[0] . '</strong> : ' . htmlentities($_POST[$pk]);
		else if ($pa[1] == true)
			$errors[] = sprintf($errorMsg, $pa[0]);
		
		continue;
	}
	
	// must be just a normal input so add it
	
	$messageArray[] = '<strong>' . $pa[0] . '</strong> : ' . htmlentities($_POST[$pk]);
	
}


// If we didn't have any errors occur we can start to set up the message

if (!count($errors)) 
{
	$Semail = sprintf($Semail, $_POST['email']);

   $ob = md5(time() . 'masonboundary');
   $ib = md5(time() . 'masonboundary2');
   
   
   $headers = "From: ".$Semail."\n"; 
   if (!empty($TemailBcc)) $headers .= "Bcc: ".$TemailBcc."\n"; 
   $headers .= "Reply-To: <". $_POST['email'].">\n";
   $headers .= "Return-Path: <" . $_POST['email'] . ">\n";
   $headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' +0000' . "\n";
   $headers .= 'X-Mailer: Solid Masonry' . "\n";
   
   $headers .= 'Mime-Version: 1.0' . "\n";
   $headers .= 'Content-Type: multipart/alternative; boundary="' . $ob . '"' . "\n";
   $headers .= 'Content-Transfer-Encoding: 7bit' . "\n";
   
   $cnt = $content;
   
   $content = "<title>$Semail</title>\n\n\n";
   $content .= "<body style='font-family: verdana; font-size: 9pt;'>\n\n";
   $content .= "<h1 style='font-size:1.1em'>Someone Has Contacted you!</h1>\n\n\n";
   
 // loop through the messages
 
 foreach ($messageArray as $msg)
 	$content .= $msg . "\n\n<br /><br />";   
  
   $content .= "Your Sincerely,\n\n<br /><br />";
   $content .= "Your Website";
   
   
   $message = strip_tags($content) . "\n" . '--' . $ob . "\n";
   
   $message .= 'Content-Type: text/plain; charset=iso-8859-1' . "\n";
   $message .= 'Content-Transfer-Encoding: 7bit' . "\n\n";
   $message .= strip_tags($content) . "\n" . '--' . $ob . "\n";
  
   $message .= 'Content-Type: text/html; charset=charset=iso-8859-1' . "\n";
   $message .= 'Content-Transfer-Encoding: 7bit' . "\n\n";
   $message .= $content . "\n" . '--' . $ob . '--';

   
   mail($Temail, $subject, $message, $headers); 
   header('Location: ' . $successURL);
}

}
function check_email($email) 
{  // First, we check that there's one @ symbol, 
  // and that the lengths are right.
  if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
	// Email invalid because wrong number of characters 
	// in one section or wrong number of @ symbols.
	return false;
  }
  // Split it into sections to make life easier
  $email_array = explode("@", $email);
  $local_array = explode(".", $email_array[0]);
  for ($i = 0; $i < sizeof($local_array); $i++) {
	if
(!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&
↪'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",
$local_array[$i])) {
	  return false;
	}
  }
  // Check if domain is IP. If not, 
  // it should be valid domain name
  if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
	$domain_array = explode(".", $email_array[1]);
	if (sizeof($domain_array) < 2) {
		return false; // Not enough parts to domain
	}
	for ($i = 0; $i < sizeof($domain_array); $i++) {
	  if
(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|
↪([A-Za-z0-9]+))$",
$domain_array[$i])) {
		return false;
	  }
	}
  }
  return true;
}
?>					

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php

if (count($errors))
{
	echo '<div style="border: solid 1px red;padding: 2em;">
		<h1 style="font-size: 1.2em;">Some Errors Occurred</h1>
		<ul>';
	
	foreach ($errors as $err)
		echo '<li>', $err, '</li>';
		
		echo '</ul>
		<a href="', $returnURL , '" onclick="window.history.back(); return false;">Go Back and try again</a>
		</div>';
}
?>


</body>
</html>

Attached File(s)


This post has been edited by Rakuli: 18 February 2008 - 02:40 AM


#6 User is offline   friendd Icon

  • Fresh Squeezed
  • PipPip
  • Group: Members
  • Posts: 25
  • Joined: 14-February 08
  • Gender:Male
  • Location:York

Posted 20 February 2008 - 12:29 PM

Rakuli,
I have been trying to do a contact form on my website but kept getting confused, after reading this thread it has worked first time.

Thankyou for the explainations on the .php download.

Cheers

Daniel
0

#7 User is offline   Rakuli Icon

  • Community Director
  • Icon
  • Group: Community Director
  • Posts: 1,378
  • Joined: 13-February 08
  • Gender:Male
  • Location:Catching the squeezed drips downunder.

Posted 20 February 2008 - 01:12 PM

Cool, glad it helped. I will look at making this form more generic and pinning the thread as it is an often asked question -- I know c010depunkk has his own way of doing this and has written a good post before. :)

#8 User is offline   karinne Icon

  • Valued Member
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 5,373
  • Joined: 13-February 08
  • Gender:Female
  • Location:quecque part dans l'Quebec in Canada eh?

Posted 20 February 2008 - 01:24 PM

We could have both of them. As we all know, there's many way of doing things in this field. So ... Rakuli and c010depunkk, maybe you guys could create another thread and pin it. Put both ways in there or a thread for each? Whatever. You guys decided.
0

#9 User is offline   902 Icon

  • Squeezing
  • PipPipPip
  • Group: Members
  • Posts: 66
  • Joined: 14-February 08

Posted 21 February 2008 - 07:44 AM

That contact form didn't work for me so I must be doing something wrong.

Is there one with just a couple of fields (name, email, message) and the security letter image, that I could toy with?
0

#10 User is offline   friendd Icon

  • Fresh Squeezed
  • PipPip
  • Group: Members
  • Posts: 25
  • Joined: 14-February 08
  • Gender:Male
  • Location:York

Posted 27 February 2008 - 03:42 PM

Since I have used the form above, I have had some Junk mail.

Only 2 emails, advertising there businesses. Have they just came across my website or is there a program that searches for mail forms?

Cheers

Dan
0

#11 User is offline   Marc Icon

  • Squeeze Machine
  • PipPipPipPipPip
  • Group: Members
  • Posts: 790
  • Joined: 13-February 08
  • Gender:Male
  • Location:Scotland, UK

Posted 27 February 2008 - 05:01 PM

Well, I don't see how a robot should be submitting through the form, but you can put some simple addition on that form to see if it's human or computer.

By the way, are you printing an Email address anywhere on your website?
0

#12 User is offline   friendd Icon

  • Fresh Squeezed
  • PipPip
  • Group: Members
  • Posts: 25
  • Joined: 14-February 08
  • Gender:Male
  • Location:York

Posted 28 February 2008 - 11:43 AM

Yes i do have the email address text form.

I could do a pic of the email address.

Does a program search for email addresses.

Cheers

Daniel
0

#13 User is offline   Rakuli Icon

  • Community Director
  • Icon
  • Group: Community Director
  • Posts: 1,378
  • Joined: 13-February 08
  • Gender:Male
  • Location:Catching the squeezed drips downunder.

Posted 28 February 2008 - 11:41 PM

Yes, the spamming robots traverse the web looking for patterns that point to it being an email adress (ie. bit of text then an @ sign some more text and a dot or two).

It is also possible for robots to be programmed to submit forms as well, simply filling all the text boxes and hitting submit. One way to avoid this from happening is to implement something that only a human could get. The Web Squeeze uses a question (What is better with Coffee?) to which the user has to answer sugar or salt. A robot would not pick up on this and just add random spammy text.

The other way is to use a randomly generated image that contains numbers/letters that need to be placed in a form input. A robot generally cannot pick characters out of an image.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic


Page 1 of 1
Trackbacks
Trackback URL Trackback Date Total Hits
No trackbacks were found
Page 1 of 1

Similar Topics
  Topic Started By Stats Last Post Info
New Replies Icon Php - Phpbb Form Instalationon An Iis6
I don't know why I'm not using .net :(
thesealportalteam Icon
  • 4 Replies
  • 3,793 Views
Hot Topic (New) Icon Email Submission Form 902 Icon
  • 14 Replies
  • 3,078 Views
New Replies Icon Why Is The Home Page Title Diffrent Form The Rest Of This Site?
The Web Squeeze - Title
thesealportalteam Icon
  • 5 Replies
  • 1,632 Views
Locked Topic Icon Attachments Php Form Mail - C010depunkk's Version
a small tutorial on how to create an email form using PHP
c010depunkk Icon
  • 3 Replies
  • 1,736 Views
New Replies Icon How To Setup Email On Local Server? djeyewater Icon
  • 5 Replies
  • 2,302 Views

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users