...

View Full Version : PHP/Flash guidance, please



SteveH
12-28-2007, 03:32 PM
Hello

I have many questions to ask about PHP, but one thing at a time.

On a Windows server I have a Flash 'contact form' with the following (input text) fields: fullname, email, subject, country, message. I have given them the following 'Instance' names: name_txt, email_txt, subject_txt, country_txt, and message_txt.

I have also given them the following variable names: fullname, email, subject, country, message.

I have a script which my Flash file CAN communicate with. I know this because when I complete the Flash contact form I receive a message in my inbox.

However, in the email I cannot see what the site visitor has input into the 'contact form' fields, meaning that PHP is not extracting information from them.

This is the script I have at the moment:

<?php

//create short variable names
$name=$_POST['name'];
$email=$_POST['email'];
$subject=$_POST['subject'];
$country=$_POST['country'];
$message=$_POST['message'];
$name=trim($name);
$email=trim($email);
$subject=StripSlashes($subject);
$country=StripSlashes($country);
$message=StripSlashes($message);

/*#########
modify the next line with your own email address
###########*/

$toaddress='myEmail@wherever.com';


if (preg_match ("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn |bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk| dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs |gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr| kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum |mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr |pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf |tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za| zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $email)) {
mail($toaddress,$subject,$country,$message,"From: $name <$email>\r\nReply-To: $email\r\nReturn-Path: $email\r\nCc: $email\r\n");
//clear the variables
$name='';
$email='';
$subject='';
$country='';
$message='';
echo "response=passed";
} else {
echo "response=invalid";
exit;
}

?>

What I would like to ask is do I need to replace:

$name=$_POST['name'];
$email=$_POST['email'];
$subject=$_POST['subject'];
$country=$_POST['country'];
$message=$_POST['message'];


with this:


$_REQUEST['fullname'];
$_REQUEST['email'];
$_REQUEST['subject'];
$_REQUEST['country'];
$_REQUEST['message'];

And finally, where do I begin to remove/end the email validity check in the above script? My own Action Script in Flash does this, so I do not need it here.

Many thanks.

Steve

mlseim
12-30-2007, 01:48 AM
$_REQUEST[' ']; is not recommended because it opens to all or any incoming data.

I would try $_GET first (assuming $_POST does not work).

As a last resort, try $_REQUEST

=================

Your error checking problem? ....

Take this part:
if (preg_match ("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn |bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk| dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs |gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr| kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum |mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr |pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf |tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za| zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $email)) {
mail($toaddress,$subject,$country,$message,"From: $name <$email>\r\nReply-To: $email\r\nReturn-Path: $email\r\nCc: $email\r\n");
//clear the variables
$name='';
$email='';
$subject='';
$country='';
$message='';
echo "response=passed";
} else {
echo "response=invalid";
exit;
}

And make it this ...

mail($toaddress,$subject,$country,$message,"From: $name <$email>\r\nReply-To: $email\r\nReturn-Path: $email\r\nCc: $email\r\n");
//clear the variables
$name='';
$email='';
$subject='';
$country='';
$message='';
exit;

You have some other issues too ...

Like, don't let them enter the subject, do that yourself.
Put their subject with the message instead.
Don't let them enter who the email goes to ... only
who the email is from.

Hard-code the subject, and the "to" address.


.

SteveH
12-30-2007, 03:17 PM
Hello mlseim

Many thanks for your informative post.

I do actually have my own 'to' address (as oposed to the 'from' address) here:

$toaddress='myEmail@wherever.com';

but I will remove it since it looks better the way you have it, that is:

mail($toaddress,$subject,$country,$message

In order to include a CC or BCC, would I include (in the above line, that is: mail($toaddress,$subject, etc etc etc), the following (as, at some stage, I will attempt to have the email HTML formatted):

$headers .= "\r\nCc: he@$hisdomain.com";
$headers .= "\r\nBcc: her@$herdomain\r\n\r\n";

Many thanks again mlseim and all the best for 2008!

Steve

mlseim
12-30-2007, 05:38 PM
Included just like they have in their example I think ...

mail($toaddress,$subject,$country,$message,"From: $name <$email>\r\nReply-To: $email\r\nReturn-Path: $email\r\nCc: $email\r\n");

$header would be the part within quotes.

For HTML email, use Google to search for: PHP HTML email

There are some mime type things that need to be done.

SteveH
12-31-2007, 07:46 PM
Many thanks again mlseim. Grateful for your help.

Cheers

Steve

StupidRalph
12-31-2007, 09:22 PM
Also, please visit this link (http://www.codingforums.com/showthread.php?t=68462).

mlseim
12-31-2007, 11:43 PM
Also know that we didn't even get into the part about
spammers and forms ... you'll have to cross that bridge
when you get there.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum