# How To - Create A Contact Form The Sends To My Email Address...



## Jaymie1989 (Mar 25, 2007)

Hi,

How do i create a form with a pull down menu and a text box and area that will send to my email when they click submit?

Thanks,

Jay:wave:


----------



## Redcore (Aug 14, 2007)

What do you mean by "pull down menu" though?


----------



## Jaymie1989 (Mar 25, 2007)

with options on the subject like this one http://www.techsupportforum.com/sendmessage.php

but for the subject i would like it as a pull down menu.


----------



## Redcore (Aug 14, 2007)

Wrote/tested it real quick - hopefully it's all okay. It emailed fine, at least.

*email.php*

```
<?php
if(isset($message)){

// ALWAYS clean the POST variables of any HTML tags first.
// And here we do it in one easy step.
$_POST = array_map('strip_tags', $_POST);

// get the posted variables
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

// to recipients - THIS IS YOU!
$to = '[email protected]';

// To send html mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Your name <' . $to . '>' . "\r\n";
$headers .= 'From: ' . $name . '<' . $from . '>' . "\r\n";
$headers .= 'Cc:' . "\r\n";
$headers .= 'Bcc:' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);

// tell them that it's okay
echo "<center><b>The email has been sent successfully</b></center>";
}else{
?> 
<form id="feedbackform" name="feedbackform" method="post" action="email.php">
  <label> Your Name<br /> 
  <input name="name" type="text" id="name" maxlength="30" />
  <br />
  <br />
  Your Email <br />
  <input name="from" type="text" id="from" maxlength="30" />
  <br />
  <br />
  Subject<br />
  <select name="subject" id="subject">
    <option value="Site Feedback" selected="selected">Site Feedback</option>
    <option value="Registration Problems">Registration Problems</option>
    <option value="Advertisement Inquiry">Advertisement Inquiry</option>
    <option value="Computer Help">Computer Help</option>
    <option value="Writers Account">Writers Account</option>
    <option value="Other">Other (explain) </option>
  </select>
  </label>
  <p>Message<br />
    <label>
      <textarea name="message" cols="50" rows="5" id="message"></textarea>
    </label>
  </p>
  <p>
    <label>
    <input type="submit" name="Submit" value="Submit" />
    </label>
  </p>
</form>
<? ;} ?>
```


----------



## Jaymie1989 (Mar 25, 2007)

What do i save it as??

HTML Page,
Web Pages,
Dynamic Website Template,
ASP Files,
ASPX Files,
Js Script,
VB Script,
CSS or 
XML 

??


----------



## Redcore (Aug 14, 2007)

Redcore said:


> *email.php*


^^^

Plus the code was wrapped in PHP tags...:grin:


----------



## Jaymie1989 (Mar 25, 2007)

I had no option to save it as php, or have i got to do it in dreamweaver?


----------



## Redcore (Aug 14, 2007)

What program are you using? If it doesn't support PHP...that's not a good thing :S Dreamweaver is nice, but there are alternatives out there. Perhaps I will compile a decent list of programs sometime and post them.

You can always copy it into Notepad and save as "email.php"


----------



## Jaymie1989 (Mar 25, 2007)

I was using MS Frontpage, but ill install dreamweaver but iv got to wait till my motherboard comes.


----------



## Redcore (Aug 14, 2007)

How is dreamweaver dependent upon the new mobo? Or do you just not want to deal with a new software until you finish your computer (understandably lol )


----------



## Jaymie1989 (Mar 25, 2007)

Oh no sorry, my computer is messed up and im waiting for my new mobo, so i can use it. ATM im using another computer.


----------



## KoosHopeloos (Nov 3, 2004)

@ Jaymie1989: Notepad should be working... Just copy and paste the all the code into notepad and save it as a txt-file and then change the extension to .php


----------



## Jaymie1989 (Mar 25, 2007)

ok, and i got lost, I saved it as contact (text file) then changed the extension to.php and uploaded it so it was contact.php when i uploaded it, (The link is Http://www.dj-ultra.co.uk/contact.php) When i tested it, the page changes to Http://,www.dj-ultra.co.uk/email.php and its got the problem of website not found, HELP.


also i put my email address here 



> to recipients - THIS IS YOU!
> $to = '[email protected]';


 which is [email protected] and i havnt recived the emial

I have changed the page to email.php BTW


----------



## Redcore (Aug 14, 2007)

I sent an email through 'email.php' and it did not say "Sent Successfully"

Did you change the code at all (BESIDES the $to variable)? As in, did you change the name of the message box? If you changed ANYTHING ... go ahead and post the entire page code here.


----------



## Jaymie1989 (Mar 25, 2007)

I took 3 of the subjects out and put in my email address



> <?php
> if(isset($message)){
> 
> // ALWAYS clean the POST variables of any HTML tags first.
> ...


----------



## Redcore (Aug 14, 2007)

Rather than quote, use the PHP tags.

Well it works on MY server...after testing with my email, I tested with yours...so you SHOULD be getting an email from my Gmail.

I've added a tag to give us the error...so let's see if that shows up.

*email.php*

```
<?php
if(isset($message)){

// ALWAYS clean the POST variables of any HTML tags first.
// And here we do it in one easy step.
$_POST = array_map('strip_tags', $_POST);

// get the posted variables
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

// to recipients - THIS IS YOU!
$to = '[email protected]';

// To send html mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'From: ' . $name . '<' . $from . '>' . "\r\n";
$headers .= 'Cc:' . "\r\n";
$headers .= 'Bcc:' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers) or die(mysql_error());

// tell them that it's okay
echo "<center><b>The email has been sent successfully</b></center>";
}else{
?>
<form id="feedbackform" name="feedbackform" method="post" action="email.php">
<label> Your Name<br />
<input name="name" type="text" id="name" maxlength="30" />
<br />
<br />
Your Email <br />
<input name="from" type="text" id="from" maxlength="30" />
<br />
<br />
Subject<br />
<select name="subject" id="subject">
<option value="Site Feedback" selected="selected">Site Feedback</option>
<option value="Forum Registration Problems">Registration Problems</option>
<option value="Other">Other (explain) </option>
</select>
</label>
<p>Message<br />
<label>
<textarea name="message" cols="50" rows="5" id="message"></textarea>
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</p>
</form>
<? ;} ?>
```


----------



## Jaymie1989 (Mar 25, 2007)

Hey, i got your email just waiting to see if mine comes through


----------



## Redcore (Aug 14, 2007)

So the code is fine, then.

If you don't get the email from your server...then that's the problem. Do you have SMTP on it?


----------



## Jaymie1989 (Mar 25, 2007)

I have no idea about SMTP


----------



## Redcore (Aug 14, 2007)

Who do you host with?


----------



## Jaymie1989 (Mar 25, 2007)

streamline.net

If i can trust you, i will give you all my details that i know about my hosting and ftp and you could do it.


----------



## Jaymie1989 (Mar 25, 2007)

I have just found where the database is for my old forum,

i will PM you with the details and the login.


----------



## Redcore (Aug 14, 2007)

I'm assuming you're a "home" package user - but I didn't see anything about SMTP. You might want to email them about that and ask if it's included or if it CAN be included.

As far as doing this for you - I can spend some time on it today but I don't want you to get in the habit of coming to me to do things for you. You have to learn on your own as well.


----------



## Jaymie1989 (Mar 25, 2007)

Sorry my last 2 posts were about the forum that is half way through being setup, the one where the database needs to be created. with this thread its just doing the SMTP


----------



## Jaymie1989 (Mar 25, 2007)

I will contact my hosting provider about SMTP and see what they say.


----------

