Help - Search - Members - Calendar
Full Version: PHP Help
HTMLHelp Forums > Programming > Server-side Scripting
MickeyG
Hey all,

Certainly not a PHP wizard here. Having a little issue with this simple email form.

http://www.kidsoffchemicals.com/contacts.htm

It was placed in an IFRAME by the previous designer and I decided to just roll with it as the client doesn't want to have me do too much work on it right now. Anyways, I think I've done something wrong in the form. Here is the form HTML and PHP.

Any help greatly appreciated. Thanks!

CODE

<table width="350px" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="send_contact.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td>Name</td>
<td>:</td>
<td><input name="name" type="text" id="name" size="35"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="customer_mail" type="text" id="customer_mail" size="35"></td>
</tr>
<tr>
<td width="16%">Phone</td>
<td width="2%">:</td>
<td width="82%"><input name="phone" type="text" id="phone" size="35"></td>
</tr>
<tr>
<td>Message</td>
<td>:</td>
<td><textarea name="message" cols="32" rows="4" id="message"></textarea></td>
</tr>

<tr>
<td height="27">&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form></td>
</tr>
</table>



Here is the PHP

CODE

<?php


// Mail of sender
$mail_from="$customer_mail";

// From
$header="from: $name <$mail_from>";

// Contact phone
$phone ="$phone";

// Message
$message="$message";


// Enter your email address
$to ='mickey@i9creative.com';

$send_contact=mail($to,$phone,$message,$header);

// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){


echo "We've recived your contact information";

}
else {
echo "ERROR";
}
?>
Christian J
Move topic to the Server-side Scripting forum.
Frederiek
See http://www.w3schools.com/PHP/php_mail.asp.
Brian Chandler
It looks as though the script was written using "magic variables" (wrong word: sorry can't remember the name). So in the form you have:

CODE

<td><input name="customer_mail" type="text" id="customer_mail" size="35"></td>


This sends a POST argument to the script with the name customer_mail. To access it, the script normally needs to use $_POST['customer_mail']. But your script has just:

CODE

// Mail of sender
$mail_from="$customer_mail";


This is a shortcut version using the "magic variables" option. This is a securitly weakness (because any variable you forgot to set can be faked by sending it in a form request), so it is usually switched off these days. Probably replacing $customer_mail by $_POST['customer_mail'] will start it working.

The script is pretty odd, btw. What on earth is the point of copying a string variable to another by writing $a = "$b"; ... none at all that I can see. It also includes absolutely no protection against various spam abuses. I would start again, somewhere else.
Christian J
QUOTE(Brian Chandler @ Aug 11 2009, 11:37 AM) *

It looks as though the script was written using "magic variables" (wrong word: sorry can't remember the name).

Are you thinking of register globals? http://php.net/manual/en/ini.core.php#ini.register-globals
Brian Chandler
QUOTE(Christian J @ Aug 11 2009, 09:29 PM) *

QUOTE(Brian Chandler @ Aug 11 2009, 11:37 AM) *

It looks as though the script was written using "magic variables" (wrong word: sorry can't remember the name).

Are you thinking of register globals? http://php.net/manual/en/ini.core.php#ini.register-globals



Right, right, I knew I remembered it. If you just rearrange the vowels and consonants a bit (as Erik von Daniken once said) you can see the name is basically the same.
MickeyG
Whew. Looks like I found the right group. You guys are speaking greek to me already. I'm a total PHP novice. I got the basics for this form from here...

http://www.phpeasystep.com/phptu/8.html

Not so good????

I know there are form hosting services out there, but I'm not a big fan of having my clients website tied to some other online service if possible. So I thought I'd try to implement the form myself.

So if that tutorial/sample is not so good, does somebody have a good one? (Frederiek, I'll check that one out too. Thanks.)

Thanks again for chiming in.
MickeyG
Oh. One thing I see is that I changed the names of some of the titles, but I didn't think that would affect the functionality of the form. Except where the Subject is confirmed. But then, I'm guessing that's just a minor portion of the problem. Right?
Frederiek
As long as the PHP variables point to the correct form elements.

Maybe you're better off to read through http://devzone.zend.com/node/view/id/627 (PHP for beginners). Or google for "php form tutorial".
Brian Chandler
CODE

// Contact subject
$subject ="$subject";


Well, this is just a sample of the "programming" on this site. What on earth is the above supposed to do?

Um, suppose $subject has the string value "Tennis club". Then this evaluates the string
"$subject", in which $subject is replaced by the string [Tennis club], and since there is nothing else in the string except the variable $subject, the whole string evaluates to "Tennis club". It then assigns this to the variable $subject, which already has exactly this value. So the end effect is precisely nothing. It looks as though someone here is seriously confused.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.