Jump to content

[SOLVED] Email Contact Form


lisacleverley

Recommended Posts

Hi and thanks for looking.

 

Basically I'm trying to add a contact form to my website and I downloaded the PHP for it off a website. Although I'm trying to configure it so it works in with my website. I have no idea about php coding I'm afraid so I have no idea what I'm doing so I'd like a little help in configuring this so it will work.

 

The test page for the contact form is here: http://www.lisacleverley.com/email/contact.htm

 

The php coding for this is as follows:

 

<?php
	/*******************************************************************************
	*                                                                              *
	*                           Simple PHP Contact Form                            *
	*                          (c) Copyright Korske 2006                           *
	*                                                                              *
	*                                www.korske.com                                *
	*                                 Version 1.00                                 *
	*                                                                              *
	*******************************************************************************/

	/*******************************************************************************
			  This is a basic PHP Script that allows you to setup your own 
							 contact form on your website
	*******************************************************************************/


//Configuration
    $email_address = "myemailaddress@email.com"; //This should be changed to your email address.
    $subject_prefix = "Website Contact";  //This will be the subject prefix of all emails. default "Website Contact - User Subject

// --- Do not modify below ---
//Collects varibles from previous page.

    $name = $_POST['name'];
    $email = $_POST['email'];
    $subject = $subject_prefix . $_POST['subject'];
    $message = $_POST['message'];
//This part should prevent malicous doings.
//Most servers are setup in such a way that this section is not needed but its a good security precaution to have.
   $from = urldecode($email);
   if (eregi("\r",$from) || eregi("\n",$from)){
           print "Malformed Headers were detected.";
        exit;
   }
//This part sends the email to you.
    mail($email_address, $subject, $message, "From: $name <$email>\nX-Mailer: Simple PHP Contact Form 1.0 (www.korske.com)");

//Redirects to sent.htm  
    header("Location: sent.htm")

?> 

 

Please, pretty please could someone help with this? Maybe add the spam blocking too (CAPTCHA system?) I would be very, very grateful. When I used the prefix page the download came with it's fine. When I updated and added my own fields on the contact.htm file, it don't. I'm assuming that the php file needs to be updated to reflect the options on the htm page but I don't know how, or where to start.

 

Thanks,

Lisa

Link to comment
Share on other sites

OK

 

Really we could do with seeing your html form.

 

But in its absense let me make the following clear.

 

The html form has an action attached (or should have) to the <form> tag.  Make sure this points to the php file.

 

The <input> tags all should have a name value ie

<input type="text" name="Your Name" />

 

Where each element has a name you need to make sure that there is a

 

$something= $_POST['something'];

 

that corresponds with it.

 

ie $name=$_POST['Your Name'];

 

This lets PHP identify the field in the form to the the posted information from.

 

Sort all that out and come back to us.

 

Will

Link to comment
Share on other sites

i'm sorry i don't really understand your problem. please be more specific.

 

 

p.s.  i love your macros.

lol Thanks.

 

Basically I downloaded the php script shown above (the paste) and it came with a basic form. The form was just fields for Name, Email and Comments. Which I don't want. I want my fields to be as the test contact form I linked to (http://www.lisacleverley.com/email/contact.htm)

 

I'd like the fields to be..

Name,

Email,

Type of event (drop down with 9 selections),

Date of event,

Comments.

 

But since I changed the basic contact.htm to the one with fields of my own. The php script doesn't email me. Or it does email me but the email is completely blank!

 

So what I want is if someone could look at it and change it. It must be wrong *shrug* And possibly add the CAPTCHA so it's secure, although not neccesary if you don't want to. I'd just greatly appreciate a fix at the moment.

 

Does all that make sense?

Link to comment
Share on other sites

Yeah..sorry just read the post again and actually looked at your page this time.

 

you have HTML...

 

<select name="event" size="1">

 

You need to have a $_POST statement for each name.  Here the name is "event"

 

So the PHP to get this information becomes

 

$event=$_POST['event'];

 

for the <option value=" other">Other</option>

it would be

 

$option=$_POST['other'];

 

etc.

 

FINALLY

use the $message in your code to stake these all together

 

$mesage=$event.$option.etc.etc

 

Now this is not going to be pretty!!!! but one step at a time

Link to comment
Share on other sites

OK

 

Really we could do with seeing your html form.

 

But in its absense let me make the following clear.

 

The html form has an action attached (or should have) to the <form> tag.  Make sure this points to the php file.

 

The <input> tags all should have a name value ie

<input type="text" name="Your Name" />

 

Where each element has a name you need to make sure that there is a

 

$something= $_POST['something'];

 

that corresponds with it.

 

ie $name=$_POST['Your Name'];

 

This lets PHP identify the field in the form to the the posted information from.

 

Sort all that out and come back to us.

 

Will

Hi Will,

 

Here's the HTML for the contact.htm file. I've just started it off where the <form> starts and ends.

 

<form action="send.php" method="post">
<table border="0" width="491">
    <tr>
        <td width="137">Name:</td>
        <td width="343">
                            <p><input type="text" size='37' name='name' /></p>
</td>

    </tr>
    <tr>
        <td width="137">Email:</td>
        <td width="343">
                            <p><input type='text' size='37' name='email' /></p>
</td>
    </tr>
    <tr>
        <td width="137" height="19">Type of event:</td>

        <td width="343" height="19">
                            <p><select name="event" size="1">
<option value=" portrait session - infant">Portrait Session - Infant</option>
<option value=" portrait session - child">Portrait Session - Child</option>
        <option value=" portrait session - maternity">Portrait Session - Maternity</option>
<option value=" portrait session - adult">Portrait Session - Adult</option>
<option value=" portrait session - pet">Portrait Session - Pet</option>
        <option value=" wedding">Wedding</option>

                                <option value=" photoediting services">Photoediting Services</option>
        <option value=" other">Other</option>
        <option value=" webmaster">Webmaster</option>
</select></p>
</td>
    </tr>
    <tr>
        <td width="137" height="4">Date of event:</td>

        <td width="343" height="4">
                            <p><input type="text" name="dateevent" size="35" />
</p>
</td>
    </tr>
    <tr>
        <td width="137" height="15">Comments:</td>
        <td width="343" height="15">
                            <p><textarea name="comments" rows="4" cols="40"></textarea></p>

</td>
    </tr>
    <tr>
        <td width="485" height="10" colspan="2">
                            <p><input type="submit" value="submit" />
</p>
</td>
    </tr>
</table>

            </form>

 

Link to comment
Share on other sites

:lol: I'm working on it.

 

Does this look right?

 

    $name = $_POST['name'];

    $email = $_POST['email'];

    $event = $_POST['event'];

    $dateevent = $_POST['dateevent'];

    $comments = $_POST['comments'];

 

I'm about to upload and test. Fingers crossed.

 

Lisa

Link to comment
Share on other sites

OK done and uploaded. Emails coming through but are completely blank  ???

 

Here's the new php file..

 

<?php
	/*******************************************************************************
	*                                                                              *
	*                           Simple PHP Contact Form                            *
	*                          (c) Copyright Korske 2006                           *
	*                                                                              *
	*                                www.korske.com                                *
	*                                 Version 1.00                                 *
	*                                                                              *
	*******************************************************************************/

	/*******************************************************************************
			  This is a basic PHP Script that allows you to setup your own 
							 contact form on your website
	*******************************************************************************/


//Configuration
    $email_address = "example@example.com"; //This should be changed to your email address.
    $subject_prefix = "Website Contact";  //This will be the subject prefix of all emails. default "Website Contact - User Subject

// --- Do not modify below ---
//Collects varibles from previous page.

    $name = $_POST['name'];
    $email = $_POST['email'];
    $event = $_POST['event'];
    $dateevent = $_POST['dateevent'];
    $comments = $_POST['comments'];
//This part should prevent malicous doings.
//Most servers are setup in such a way that this section is not needed but its a good security precaution to have.
   $from = urldecode($email);
   if (eregi("\r",$from) || eregi("\n",$from)){
           print "Malformed Headers were detected.";
        exit;
   }
//This part sends the email to you.
    mail($email_address, $subject, $message, "From: $name <$email>\nX-Mailer: Simple PHP Contact Form 1.0 (www.korske.com)");

//Redirects to sent.htm  
    header("Location: sent.htm")

?>

Link to comment
Share on other sites

all your form variable must be included in your mail($......)

however, can you please add the entire send.php or mail.php file you refer in your form.  than only i can give your directions.

Hi, thanks for the reply. The entire sent.php file is shown in this post. This is after editing it from the instructions in this thread.

 

http://www.phpfreaks.com/forums/index.php/topic,130135.msg545747.html#msg545747

 

Is that what you mean? :)

 

Lisa

Link to comment
Share on other sites

your nearly there!!!.

 

 

mail($email_address, $subject, $message, "From: $name <$email>\nX-Mailer: Simple PHP Contact Form 1.0 (www.korske.com)");

 

Think about his line.  It mails all the other bits and pieces.

You need to send a $message ...right?

well you work the rest out

So we can create a $message by saying $message="This is my message...name=".$name." and email=".$email." and event=".$event." and ....you work the rest out!

 

lol

 

am i am bad teacher???

Link to comment
Share on other sites

your nearly there!!!.

 

 

mail($email_address, $subject, $message, "From: $name <$email>\nX-Mailer: Simple PHP Contact Form 1.0 (www.korske.com)");

 

Think about his line.  It mails all the other bits and pieces.

You need to send a $message ...right?

well you work the rest out

So we can create a $message by saying $message="This is my message...name=".$name." and email=".$email." and event=".$event." and ....you work the rest out!

 

lol

 

am i am bad teacher???

Honestly, your a great teacher. Although I am going dizzy here as it's my first time doing anything php related.

 

OK I edited that part with the below..

 

    mail($email_address, $subject, $event, $dateevent, $comments "From: $name <$email>\nX-Mailer: Simple PHP Contact Form 1.0 (www.korske.com)");

 

Uploaded it to server and tried it out and now I'm getting a server error "Parse error: parse error, unexpected '\"' in /home/babiesbo/public_html/email/send.php on line 38"

Link to comment
Share on other sites

great will,  lisa please take a break and than comeback, you are almost there and hope by now you figured it out.

 

please do remember this a crap mail form.  no validation and security.  If you are ok with this its fine.  but in real projects this is a stupid programming.  sorry for my words.

Link to comment
Share on other sites

great will,  lisa please take a break and than comeback, you are almost there and hope by now you figured it out.

 

please do remember this a crap mail form.  no validation and security.  If you are ok with this its fine.  but in real projects this is a stupid programming.  sorry for my words.

I really don't know anything about php to make it secure I'm afraid. How do you add security to it? ???
Link to comment
Share on other sites

Thanks :)

 

Here's the updated send.php code...

 

<?
	/*******************************************************************************
	*                                                                              *
	*                           Simple PHP Contact Form                            *
	*                          (c) Copyright Korske 2006                           *
	*                                                                              *
	*                                www.korske.com                                *
	*                                 Version 1.00                                 *
	*                                                                              *
	*******************************************************************************/

	/*******************************************************************************
			  This is a basic PHP Script that allows you to setup your own 
							 contact form on your website
	*******************************************************************************/


//Configuration
    $email_address = "my_email_address"; //This should be changed to your email address.
    $subject_prefix = "Website Contact";  //This will be the subject prefix of all emails. default "Website Contact - User Subject

// --- Do not modify below ---
//Collects varibles from previous page.

    $name = $_POST['name'];
    $email = $_POST['email'];
    $event = $_POST['event'];
    $dateevent = $_POST['dateevent'];
    $comments = $_POST['comments'];
//This part should prevent malicous doings.
//Most servers are setup in such a way that this section is not needed but its a good security precaution to have.
   $from = urldecode($email);
   if (eregi("\r",$from) || eregi("\n",$from)){
           print "Malformed Headers were detected.";
        exit;
   }
//This part sends the email to you.
    mail($email_address, $subject, $event, $dateevent, $comments "From: $name <$email>\nX-Mailer: Simple PHP Contact Form 1.0 (www.korske.com)");

//Redirects to sent.htm  
    header("Location: sent.htm")

?> 

Link to comment
Share on other sites

REmove this line

 

mail($email_address, $subject, $event, $dateevent, $comments "From: $name <$email>\nX-Mailer: Simple PHP Contact Form 1.0 (www.korske.com)");

 

 

and replace with

 

mail("Lisa Cleveryley <".$email_address. ">",$subject_prefix,$message,"From: ".$name." <".$email.">");

Link to comment
Share on other sites

Ok thanks Will. I replaced that and it says it's emailing again. Although emails are back to being blank again. Do I need to change the $messege to $comments to reflect the form in the html page? The part where someone enters a messege is called 'comments'.

 

Sorry for all the hassle I'm causing.

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.