Welcome Guest!

If you do not have an account yet on The Web Squeeze forums, please Register! It’s FREE and there are many benefits:

  • Receive Fast Advice
  • Learn Programming Languages
  • Get Professional Website Reviews
  • Quick Troubleshooting Assistance

> Php For Email Form

This is a discussion on Php For Email Form, within the PHP section. This forum and the thread "Php For Email Form" are both part of the Programming Your Website category.

 
Reply to this topicStart new topic
> Php For Email Form
xkatx21x
post Feb 17 2008, 09:26 PM
Post #1


New Squeeze
*

Posts: 4
Joined: 15-February 08


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.gif . 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.gif

Thank you in advance for any help or advice received.
Go to the top of the page
 
+Quote Post
Rakuli
post Feb 17 2008, 09:46 PM
Post #2


Squeeze Machine
Group Icon

Posts: 766
Joined: 13-February 08
From: Catching the squeezed drips downunder.


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.


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
xkatx21x
post Feb 17 2008, 10:01 PM
Post #3


New Squeeze
*

Posts: 4
Joined: 15-February 08


QUOTE (Rakuli @ Feb 17 2008, 10: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.


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.gif
Go to the top of the page
 
+Quote Post
c010depunkk
post Feb 18 2008, 02:02 AM
Post #4


Rapid Squeezer
Group Icon

Posts: 199
Joined: 14-February 08
From: Willich, Germany


hmm... maybe we should make a sticky. This is probably the first of many similar questions... biggrin.gif


--------------------
www.c010depunkk.com ~ the hangout of a web developer
Go to the top of the page
 
+Quote Post
Rakuli
post Feb 18 2008, 02:38 AM
Post #5


Squeeze Machine
Group Icon

Posts: 766
Joined: 13-February 08
From: Catching the squeezed drips downunder.


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.

CODE
<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.

CODE
<?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>


This post has been edited by Rakuli: Feb 18 2008, 02:40 AM
Attached File(s)
Attached File  contactForm.php ( 7.4K ) Number of downloads: 4
 


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
friendd
post Feb 20 2008, 12:29 PM
Post #6


Fresh Squeezed
**

Posts: 13
Joined: 14-February 08
From: York


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
Go to the top of the page
 
+Quote Post
Rakuli
post Feb 20 2008, 01:12 PM
Post #7


Squeeze Machine
Group Icon

Posts: 766
Joined: 13-February 08
From: Catching the squeezed drips downunder.


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. smile.gif


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
karinne
post Feb 20 2008, 01:24 PM
Post #8


Co-Founder
Group Icon

Posts: 3,107
Joined: 13-February 08
From: my little igloo up north


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.


--------------------
a web design portfolio | web non-sense - REDESIGNED!
I'm also on: del.icio.us | flickr | virb | facebook | twitter
The Web Squeeze is also on: twitter | virb | facebook | stumbleupon
Go to the top of the page
 
+Quote Post
902
post Feb 21 2008, 07:44 AM
Post #9


Squeezing
***

Posts: 65
Joined: 14-February 08


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?
Go to the top of the page
 
+Quote Post
friendd
post Feb 27 2008, 03:42 PM
Post #10


Fresh Squeezed
**

Posts: 13
Joined: 14-February 08
From: York


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
Go to the top of the page
 
+Quote Post
Marc
post Feb 27 2008, 05:01 PM
Post #11


Squeeze Machine
*****

Posts: 574
Joined: 13-February 08
From: Scotland, UK


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?


--------------------
Thanks,
Marc
Go to the top of the page
 
+Quote Post
friendd
post Feb 28 2008, 11:43 AM
Post #12


Fresh Squeezed
**

Posts: 13
Joined: 14-February 08
From: York


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
Go to the top of the page
 
+Quote Post
Rakuli
post Feb 28 2008, 11:41 PM
Post #13


Squeeze Machine
Group Icon

Posts: 766
Joined: 13-February 08
From: Catching the squeezed drips downunder.


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.


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
If you found The Web Squeeze to be helpful, please donate so we can keep this site FREE, FRESH, and fortified with Web Design & Development info!
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   4 thesealportalteam 784 20th February 2008 - 09:00 AM
Last post by: thesealportalteam
No new   14 902 724 22nd February 2008 - 02:45 AM
Last post by: c010depunkk
No New Posts   5 thesealportalteam 422 22nd February 2008 - 11:48 PM
Last post by: Monie
No New Posts   3 c010depunkk 452 21st February 2008 - 09:41 AM
Last post by: c010depunkk
No New Posts   4 Jason 280 25th February 2008 - 08:32 AM
Last post by: thesealportalteam