Jump to content

help, please on a form


madox

Recommended Posts

Guys,

I am new to php and I am sure this question has come up,  I don't see why it is not working. I have this in two parts:

 

Here is my html code for the form

<form action="contact.php" method="get"> 

                                                            <div class="container1">

                                                                <div class="col-3">

                                                                    <div class="h"><input type="your_name" value="name" /></div>

                                                                    <div class="h"><input type="your_email" value="e-mail" /></div>

                                                                    <div class="h"><input type="your_phone" value="phone" /></div>

                                                                    <div class="h"><input type="your_address" value="address" /></div>

                                                                </div>

                                                                <div class="col-4">

                                                                  <textarea name="message" cols="35" rows="35">message</textarea><br />

                                                                  <div class="fright">

                                                                  <div class="link-2"><em><b><a href="#" onclick="document.getElementById('contact.php').submit()">Send</a></b></em></div> 

                                                                        <div class="indent"><div class="link-2"><em><b><a href="#" onclick="document.getElementById('contact.php').reset()">Clear</a></b></em></div></div>

                                                                  </div>

                                                              </div>

                                                              <br class="clear" />

                                                        </div>

                                                      </form>

 

 

contact.php

<?

$subject="from ".$_GET['your_name'];

$headers= "From: ".$_GET['your_email']."\n";

$phone="from: ".$_GET['your_phone'];

$address="from: ".$_GET['your_address'];

$headers.='Content-type: text/html; charset=iso-8859-1';

mail("my-emailaddress@here"

<html>

<head>

<title>Contact letter</title>

</head>

<body>

 

<br>

  ".$_GET['message']."

</body>

</html>" , $headers);

echo ("Your message was successfully sent!");

?>

<script>

resizeTo(300, 300)

//window.close()

</script>

 

Any help would be great.

 

Link to comment
Share on other sites

Besides using the code tags and I'd like to hear what issues are arising, your form itself looks like it would never work...

                                                                    <div class="h"><input type="your_name" value="name" /></div>
                                                                   <div class="h"><input type="your_email" value="e-mail" /></div>
                                                                   <div class="h"><input type="your_phone" value="phone" /></div>
                                                                   <div class="h"><input type="your_address" value="address" /></div>

"type" isn't what you want to name your input, its the tag for what type of form object to use. try:

<input type="text" name="your_name" value="name" />

Link to comment
Share on other sites

Brian W. is right the types you have should be the names.  Do:

 




 

One more question before we proceed, why don't you use POST rather than GET?  It's easier and more secure.  All you would have to do in your contact.php script would just use:

 

//For your_name input field
$_POST['your_name'];

 

Also your code is all messed up.  You don't use starting or ending php tags.  For example you have:

 

mail("my-emailaddress@here"

 

First the here" is messed up, not even a finished line, second you're going from PHP to HTML without tags.  Maybe they're not showing up because you didn't use the code tags like i suggested.

Link to comment
Share on other sites

I added the code to the contact.php file and it didn't give me any error's.

 

Here is my contact.php code

 

<?
ini_set ("display_errors", "1");
error_reporting(E_ALL);
$subject="from ".$_GET['your_name'];
$headers= "From: ".$_GET['your_email']."\n";
$phone="from: ".$_GET['your_phone'];
$address="from: ".$_GET['your_address'];
$headers.='Content-type: text/html; charset=iso-8859-1';
mail("my-e-mail address"
<html>
<head>
<title>Contact letter</title>
</head>
<body>

<br>
  ".$_GET['message']."
</body>
</html>" , $headers);
echo ("Your message was successfully sent!");
?>
<script>
resizeTo(300, 300)
//window.close()
</script>

 

<form action="contact.php" method="get">   
                                                            <div class="container1">
                                                                <div class="col-3">
                                                                    <div class="h"><input type="text" name="your_name" value="name"></div>
                                                                    <div class="h"><input type="text" name="your_address" value="name"/></div>
                                                                    <div class="h"><input type="text" name="your_phone" value="name"/></div>
                                                                    <div class="h"><input type="text" name="your_address" value="name" /></div>
                                                                </div>
                                                                <div class="col-4">
                                                                  <textarea name="message" cols="35" rows="35">message</textarea><br />
                                                                  <div class="fright">
                                                                  		<div class="link-2"><em><b><a href="#" onclick="document.getElementById('contact.php').submit()">Send</a></b></em></div>   
                                                                        <div class="indent"><div class="link-2"><em><b><a href="#" onclick="document.getElementById('contact.php').reset()">Clear</a></b></em></div></div>
                                                                  </div>
                                                              </div>
                                                              <br class="clear" />
                                                         </div>
                                                      </form>

Link to comment
Share on other sites

Okay first thing, you need to learn when to use the <?php ?> tags.  For example:

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);
$subject="from ".$_GET['your_name'];
$headers= "From: ".$_GET['your_email']."\n";
$phone="from: ".$_GET['your_phone'];
$address="from: ".$_GET['your_address'];
$headers.='Content-type: text/html; charset=iso-8859-1';
mail("my-e-mail address"

 

Needs to be:

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);
$subject="from ".$_GET['your_name'];
$headers= "From: ".$_GET['your_email']."\n";
$phone="from: ".$_GET['your_phone'];
$address="from: ".$_GET['your_address'];
$headers.='Content-type: text/html; charset=iso-8859-1';
mail("my-e-mail address"    //WTF is this!?
?>


 

See the difference?

 

Link to comment
Share on other sites

Sorry I fixed my code. I must have deleted it somehow.

Here is the code again, plus I fix the tag.

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
$subject="from ".$_GET['your_name'];
$headers= "From: ".$_GET['your_email']."\n";
$phone="from: ".$_GET['your_phone'];
$address="from: ".$_GET['your_address'];
$headers.='Content-type: text/html; charset=iso-8859-1';
mail("my email address", $subject,  "
<html>
<head>
<title>Contact letter</title>
</head>
<body>

<br>
  ".$_GET['message']."
</body>
</html>" , $headers);
echo ("Your message was successfully sent!");
?>
<script>
resizeTo(300, 300)
//window.close()
</script>

Link to comment
Share on other sites

Maq, I told madox to read http://us2.php.net/mail

It has a great example of what the mail() function should look like.

 

You should also make the body of your email a string than have the string in the function.

mail('youremail', $subject, $body, $headers)

also, html doesn't always go well in emails, many email clients don't accept the tags. please some one inform me of how to change that if there is a way.

line breaks can be accomplished with \n\r

Link to comment
Share on other sites

Kind of like what Brian W said, it's much easier to format the mail variables separate from the function (not tested!):

 

$headers "whatever you need";
$subject = "Hello there";
$my_email = "tim@yahoo.com";
$message = "

Contact letter




  ".$_GET['message']."

";

mail("my email address", $subject, $message, $headers);

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.