GetDotted Domains

Viewing Thread:
"Form-to-Mail script for Flash website"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Fri 27/02/09 at 16:27
Regular
Posts: 9
I’m building a Flash website and am having a problem making a form-to-mail script work. Following text input, the submit button is supposed to link with a PHP script. I’ve uploaded this to the server and placed it in the htdocs folder rather than the cgi-bin. Nothing happens when the button is clicked.

I doubt if there’s any reason why the Freeola server would reject the script, so I can only assume I’ve written it wrongly. With only three fields (Name, Company, Email) it should be fairly short and I’m wondering if anyone out there can give me a sample of the basic code. I’d very much appreciate some help.
Wed 04/03/09 at 17:31
Regular
"Ctrl, Alt, Woof"
Posts: 212
Hi Ardee,

Pleased it's working.

JTD
Wed 04/03/09 at 17:05
Regular
Posts: 9
Cracked it!

The PHP code that works for me is as follows:

$fn= $_REQUEST["fn"];
$sn= $_REQUEST["sn"];
$t= $_REQUEST["t"];
$c= $_REQUEST["c"];
$email= $_REQUEST["email"];
$to = "[email protected]";
$subject = "Motivational Speaking Enquiries";
$body = "Forename: $fnnSurname: $snnTelephone: $tnE-mail: $emailnComments $c";


mail($to, $subject, $body, 'From: [email protected]','-f [email protected]');

?>

However, because global variables are turned off – the information passed from the flash file to the php script wouldn’t work. Since PHP 5.0, apparently, these have been turned off by default to improve security. The normal way around this is to use GET or POST or HTTP POST to pull the variables from the array that’s holding them but this wouldn’t work with flash.

It seems that it needs a different command called REQUEST which is a combination of both GET and POST to work.

Once again, thanks to Jim and t1mmie for their help.
Wed 04/03/09 at 14:49
Regular
"Ctrl, Alt, Woof"
Posts: 212
Ardee,

Right, good stuff so far, now you need to check what, if anything, is being passed to the form. I regulary use this script to work out what is being passed from the submitted form.

Create a page called processform.php and copy the below code into it. Then call processform.php from your submit action.


<?php
/* Script name: processform.php
* Description: Script displays all the information passed
* from a form.
*/

foreach ($_POST as $field => $value)
{
echo "P:$field = $value<br>";
}
foreach ($_GET as $field => $value)
{
echo "G:$field = $value<br>";
}
foreach ($_REQUEST as $field => $value)
{
echo "R:$field = $value<br>";
}
?>


It might shed some more light on the matter.

JTD
Wed 04/03/09 at 14:20
Regular
Posts: 9
Thanks t1mmie and JimTheDog

I'm pleased to report that things seem to be moving in the right direction. I can now send/receive the form. The only problem is that all the fields are blank. Trying to work out why.
Wed 04/03/09 at 13:12
Regular
Posts: 391
Ardee wrote:

> 2. The submit action in flash should therefore point to
> http://www.motivationalspeaking/htdocs/mail.php

What Jim said - so you'd need to use this instead:

http://www.motivationalspeaking/mail.php

But all files still stay in your htdocs folder.
Wed 04/03/09 at 12:17
Regular
"Ctrl, Alt, Woof"
Posts: 212
Hi Ardee,

You don't need the htdocs part of the path. htdocs is the root of your directory and therefore doesn't need to be included in the path after the domain.

You are correct about where the files are located though.

JTD
Wed 04/03/09 at 11:49
Regular
Posts: 9
Afraid it's still not working. Can I just check a couple of things:

1. All files (html.swf and php) should be in the htdocs directory on the server.

2. The submit action in flash should therefore point to http://www.motivationalspeaking/htdocs/mail.php

Is that correct? Appreciate your help.
Wed 04/03/09 at 09:52
Regular
Posts: 391
Ok, try:


<?php

$fn=$_REQUEST["fn"];
$sn=$_REQUEST["sn"];
$t=$_REQUEST["t"];
$c=$_REQUEST["c"];
$email=$_REQUEST["email"];
$to="motivationalspeaking.co.uk";
$subject="Motivational Speaking Enquiries";
$body="
Forename: $fn
Surname: $sn
Telephone: $t
E-mail: $email
Comments: $c
";
$from="From: [email protected]"

if (mail($to, $subject, $body, $from)) {

echo "<p>Message sent!</p>";

} else {

echo "<p>Message failed!</p>";

}
?>


If that doesn't work, then your Flash your fields in Flash don't have the same name and ID.

Make sure that everything in Flash is named the same in every way possible, so make sure that the comment box is named 'c', for example.
Wed 04/03/09 at 09:20
Regular
"Ctrl, Alt, Woof"
Posts: 212
Is it genrating an error or just not doing anything?

If you replace your variables with hard code does it work then?

I often use this script to debug:

<script language="JavaScript" type="text/javascript">
alert("<?php echo $message;?>");
</script>


It pops up with a dialogue box showing your variable contents.

Place it before the mail() statement and replace my $message with your variables. My first guess would be that one or more variables is null - but this will soon identify that.

I also note you use $_GET - does Flash use $_GET or $_POST?


JTD
Wed 04/03/09 at 09:20
Moderator
"Are you sure?"
Posts: 5,000
Hello - I'm no php (or anything else!) expert but I eventually manage to get my thirdparty formmail scripts running.

I know you said the code you're showing is stripped out - but don't you have to use the sendmail command ('/usr/sbin/sendmail') somewhere along the line?


Ignore me if I'm totally missing the point :¬)





Search Freeola Chat

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

I've been with Freeola for 14 years...
I've been with Freeola for 14 years now, and in that time you have proven time and time again to be a top-ranking internet service provider and unbeatable hosting service. Thank you.
Anthony
My website looks tremendous!
Fantastic site, easy to follow, simple guides... impressed with whole package. My website looks tremendous. You don't need to be a rocket scientist to set this up, Freeola helps you step-by-step.
Susan

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre
Feedback Close Feedback

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.