Jump to content


Contact form help!


5 replies to this topic

#1 BigDog

    Young Padawan

  • Members
  • Pip
  • 277 posts
  • Gender:Male
  • Location:Orange County, California
  • Interests:Running, building computers, PC games and BMX and programming.

Posted 24 November 2005 - 01:30 PM

<?php
//Variables - Your e-mail address (keep this file name : contact.php)
$your_email = "nbigdog2000@gmail.com";

//Show Mail Form
function showForm() {
echo "<html><head>\n"
 ."<title>Contact Us</title>\n"
 ."</head><body>\n"
 ."<font face='arial' size='2'>\n"
 ."<h1>Contact Us</h1>\n"
 ."<form method='post' action='contact.php?action=sendEmail'>\n"
 ."<table width='100%' border='0' cellspacing='0' cellpadding='4'>\n"
 ."<tr>\n"
 ."<td width='25%'><font face='arial' size='2'>Your Name:</font></td>\n"
 ."<td width='75%'><input type='text' name='name' size='40'></td>\n"
 ."</tr><tr>\n"
 ."<td width='25%'><font face='arial' size='2'>Your Email:</font></td>\n"
 ."<td width='75%'><input type='text' name='email' size='40'></td>\n"
 ."</tr><tr>\n"
 ."<td width='25%'><font face='arial' size='2'>Subject:</font></td>\n"
 ."<td width='75%'><input type='text' name='subject' size='40'></td>\n"
 ."</tr><tr>\n"
 ."<td width='25%'><font face='arial' size='2'>Message:</font></td>\n"
 ."<td width='75%'><textarea name='message' rows='10' cols='35'></textarea></td>\n"
 ."</tr></table>\n"
 ."<input type='submit' value='Send'>\n"
 ."</form></body></html>\n";
}

//Send Email
function sendEmail() {
global $your_email,$name,$email,$subject,$message;
if ( !$name | !$email | !$subject | !$message ) {
 header ("Location: contact.php");
}
else {
 $email2 = "$email ($name)";
 mail( $your_email, $subject, $message, "From: $email2");
 echo "<html><head>\n"
  ."<title>Email Sent!</title>\n"
  ."</head><body>\n"
  ."<font face='arial' size='2'>\n"
  ."<h1>Email Sent!</h1>\n"
  ."Your Email has been sent with success!\n We will contact you as soon as possible."
  ."</font></body></html>\n";
}
}

//Switch Statement
Switch ( $action ) {

Case 'sendEmail':
 sendEmail();
 Break;

Default:
 showForm();

}

?>

well, thats my code, but when it sends the email, all i get is the message!
is it possible to make it send the email like so :
Name :
Email :
Subject :
Message :
and subject be "Message from Studio 17 website"

anyone, please and thanks

#2 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 24 November 2005 - 02:22 PM

well maybe its me but u dont have $name, $email, $subject and $message define to display what has been posted

#3 BigDog

    Young Padawan

  • Members
  • Pip
  • 277 posts
  • Gender:Male
  • Location:Orange County, California
  • Interests:Running, building computers, PC games and BMX and programming.

Posted 24 November 2005 - 06:43 PM

Well, i aint much of a coder, so can you help me?

#4 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 25 November 2005 - 12:48 AM

Well, since you're not much of a coder, i'll assume you got that from some other site. So my first recommendation would be to search through the tutorial database for "mail" (specifically in the php section), there are hundreds of tutorials on it how to use this. There are some far better ways of doing this then what they used (or at least better in my opinion).

And then after doing that, take a look at: http://php.net/manua...nction.mail.php

And deadly is right in saying that none of the variables were assigned. I'm assuming it's because that script probably relied on register_globals (which is normally turned off now a days, and could be causing part of the problem).

Edited by rc69, 25 November 2005 - 12:50 AM.


#5 AZWebdesigns

    Young Padawan

  • Members
  • Pip
  • 4 posts

Posted 27 November 2005 - 11:24 AM

Tnx rc nice lil link u putt up there helpt me out !

#6 BigDog

    Young Padawan

  • Members
  • Pip
  • 277 posts
  • Gender:Male
  • Location:Orange County, California
  • Interests:Running, building computers, PC games and BMX and programming.

Posted 28 November 2005 - 07:53 PM

Now, i did this
<form action="contact.php" method="post">

  <p>Name: 
	<input type="text" name="name">
	<br>

E-mail: 
<input type="text" name = "email">
<br>
Subject:
<input type="text" name = "subject">
<br>

Message:<br>

<textarea name="message1" cols="35" rows="5" id="message1"></textarea>
<br>
<br>

<input type="submit" value="Send">
  </p>
</form>
<?

$name=$_POST['name'];

$email=$_POST['email'];

$subject=$_POST['subject'];

$message1=$_POST['message1'];

$to="nbigdog2000@gmail.com";

$message=" A Message was sent to you from your website (www.studio17inc.com). \n Name: $name \n Email: $email \n Subject: $subject \n Message: $message1";

if(mail($to,"Message from Website",$message,"From: $email\n")) {

echo "Thanks for contacting us, we will contact you A.S.A.P.";

} else {

echo "There was a problem sending your story. Please check that you filled in the form correctly.";

}

?>

i got 2 problems with this.

1. It sends two emails, 1 is blank, it just has this
A Message was sent to you from your website (www.studio17inc.com).
Name:
Email:
Subject:
Message:
and the 2nd email has the information filled.

2. http://www.competenc...o17/contact.php
if you take a look, it has the thank you there, but i havnt sent it, how can i make it so when i click send, it takes me to a new page that says error or thank you.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users