PDA

View Full Version : flash mx and php



jimw00d
January 3rd, 2003, 07:21 PM
I have been trying for a few days to obtain information about the users of sites. No success so far.

In flash I am using:

loadVariablesNum("mailPHP.php", "0", "POST");

My php code is:


<html>
<body>
<?php
$mail_to="northls@nbkayaking.com";
$browserType=$HTTP_USER_AGENT;
$mediaTypes=$HTTP_ACCEPT;
?>
</body>
</html>

I know I have made an arseup somewhere.

Who knows?

Cheers


by lostinbeta to show code....
Kaotic: Use [ PHP ] [ /PHP ] (without spaces) to show your HTML and PHP code since this forum converts that.

lostinbeta
January 3rd, 2003, 08:09 PM
I don't know how Flash and PHP work together, it isn't really my area, but I think the problem lies within your PHP script, it doesn't look right to me. I just started learning PHP and created by own mailForm script, but I don't know how to write one that will work with Flash like that.

c0ldfusion
January 4th, 2003, 06:18 PM
the correct .php file would be:


<?
$mail_to="northls@nbkayaking.com";
$browserType=$HTTP_USER_AGENT;
$mediaTypes=$HTTP_ACCEPT;

echo "mail_to=\"". $mail_to ."\"&browserType=\"". $browserType ."\"&mediaTypes=\"" . $mediaTypes . "\"";
?>

the thing is you have to print the content of the variables like this:
var=var_value

for multiple variables, you can use the ampersand (&) between variables, like this: var1=var_value1&var2=var_value2

and one more thing.. in the .php file do not use <html> [..] tags.. print out only the variables and their content

have fun ;)

lostinbeta
January 4th, 2003, 06:20 PM
Even though it wasn't me having the problems, I still want to thank you for that info.

I don't work with server side flash, but am thinking about getting more into it, this is definitely good knowledge to have :)

jimw00d
January 4th, 2003, 06:57 PM
Thanks for the code. My only query is that I wanted the php file to generate an email. At the moment it only generates the code as shown in:

http://nortls.nbkayaking.com/BrowserConfig

I guess through the echo command

Would you have an idea how to use the mail() command to send the variables through email.

I seem to keep screwing the mail command up, getting errors such as:

Warning: Wrong parameter count for mail() in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 11


Regards

c0ldfusion
January 4th, 2003, 08:21 PM
the mail() php command prototype is like this:

bool mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]])

so, if you want to email 'some1@yahoo.com' with the subject 'wassup' and the message 'hello there', you would use:



if (@mail("some1@yahoo.com", "wassup", "hello there"))
echo 'email sent';
else echo "problems sending the email :/";


in your case, use:



if (@mail($mail_to,"subject",
"browser= " . $browserType . "<br>" .
"mediaTypes= " . $mediaTypes))
echo 'email sent';
else echo "problems sending the email :/";


and you'll have an email with these things :)

hope i'm being usefull :)

senocular
January 4th, 2003, 08:53 PM
... why wasnt this one moved to serverside scripting?

lostinbeta
January 4th, 2003, 08:57 PM
Very good question senocular. I didn't even notice it was in the Actionscript section.


I moved it now.

senocular
January 4th, 2003, 09:45 PM
:beam:

lostinbeta
January 4th, 2003, 11:11 PM
Thanks for the good eye ;)


::because as you can see I am missing one...lol::

jimw00d
January 5th, 2003, 11:08 AM
OK my final php code is :

<?
$ToEmail = "northls@nbkayaking.com";

$ToSubject = "Enquiry";

$EmailBody = "Sent By: $FirstName\nSenders Email: $Email\n\nMessage Sent:\n$ToComments\n";

$browserType=$HTTP_USER_AGENT;

$mediaTypes=$HTTP_ACCEPT;

mail($ToName." <".$ToEmail.">",$ToSubject, $EmailBody, "From: ".$FirstName." <".$Email.">");

?>


As you can see I have defined variables for browser type and media types. But I am having problems getting the values passed into the email. I get errors if I add thjem to the email body part of the mail command

Any pointers


Regards

c0ldfusion
January 5th, 2003, 04:38 PM
your code is a little bit confusing...

first, put the $browserType and $mediaTypes in $EmailBody.
second, what variable is $ToName ? you've used it as the first parameter in the mail() command: $ToName." <".$ToEmail.">".

if ($ToName) is not defined, then the mail() tried to send an email to an invalid address

i would explain you better, but i'm in a hurry... tomorrow i start school early :/

jimw00d
January 6th, 2003, 05:22 AM
$ToName is a variable passed into the php script through flash. The real problem I have is adding additional variables, would this work as the php body?


$EmailBody = "Sent By: $FirstName\nSenders Email: $Email\n\nMessage Sent:\n$ToComments\n\n$BrowserType=HTTP_USER_AGENT \n
$mediaTypes=$HTTP_ACCEPT\n";

I am new to php coding and this is my first meaningful script therefore I am not sure about correct form of coding etc.

Regards

jimw00d
January 6th, 2003, 09:13 AM
I've had success with:

<html>
<body>
<?php
$ToEmail = "northls@nbkayaking.com";

$ToSubject = "Enquiry";

$BrowserType = $HTTP_USER_AGENT;

$MediaTypes = $HTTP_ACCEPT;

$ServerName= $REMOTE_ADDR. " " . $REMOTE_USER;

$EmailBody = "Sent By: $FirstName\nSenders Email: $Email\n\nMessageSent:\n$ToComments\n\n$BrowserTyp e\n
$MediaTypes\n$ServerName";

mail($ToName." <".$ToEmail.">",$ToSubject, $EmailBody, "From: ".$FirstName." <".$Email.">");
?>
</body>
</html>

Only trouble is that $HTTP_ACCEPT returns */* and the BrowserType returns Mozilla rather than IE,

Any ideas?

c0ldfusion
January 6th, 2003, 04:53 PM
hmm... have no ideas on this one :((
anyone there who can help?

c0ldfusion
January 6th, 2003, 04:58 PM
hmm... it just popped out of my mind... you can use get_browser() for determining the browser type and some other stuff... maybe this will report the right browser;

i've searched right now on php.net about this function; look at the following example on how to use get_browser():



<?php
function list_array ($array) {
while (list ($key, $value) = each ($array)) {
$str .= "<b>$key:</b> $value<br>\n";
}
return $str;
}
echo "$HTTP_USER_AGENT<hr>\n";
$browser = get_browser();
echo list_array ((array) $browser);
?>


would write something like:



Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586)<hr>
<b>browser_name_pattern:</b> Mozilla/4\.5.*<br>
<b>parent:</b> Netscape 4.0<br>
<b>platform:</b> Unknown<br>
<b>majorver:</b> 4<br>
<b>minorver:</b> 5<br>
<b>browser:</b> Netscape<br>
<b>version:</b> 4<br>
<b>frames:</b> 1<br>
<b>tables:</b> 1<br>
<b>cookies:</b> 1<br>
<b>backgroundsounds:</b> <br>
<b>vbscript:</b> <br>
<b>javascript:</b> 1<br>
<b>javaapplets:</b> 1<br>
<b>activexcontrols:</b> <br>
<b>beta:</b> <br>
<b>crawler:</b> <br>
<b>authenticodeupdate:</b> <br>
<b>msn:</b> <br>


don't worry about this example, because the browser in this test was really mozilla (the test was run under linux)

so try this function...

jimw00d
January 23rd, 2003, 09:05 AM
Cold,

In a previous reply you used the echo command to display the results of my mailto() script. I would like to redirect users to another html page which will display the results of mailto().

The script I have used is:

<html>
<body>
<?php
$ToEmail = "northls@nbkayaking.com";

$ToSubject = "Enquiry";

$BrowserType = $HTTP_USER_AGENT;

$MediaTypes = $HTTP_ACCEPT;

$ServerName= $REMOTE_ADDR;

$Date= date("d/F/y\n\nH.i");

$EmailBody = "Sent By: $FirstName\nSenders Email: $Email\n\nMessage Sent:\n$ToComments\n\n$BrowserType\n$MediaTypes\n$ ServerName\n\n$Date";

mail($ToName." <".$ToEmail.">",$ToSubject, $EmailBody, "From: ".$FirstName." <".$Email.">");

if (@mail($mail_to,"subject",
"browser= " . $BrowserType . "" .
"mediaTypes= " . $MediaTypes)
header("Location: http://evolt.org"));
exit;
?>
</body>
</html>


The last section header ... I have added.

It doesn't work at the moment. How would the echo command work with the header line, or am I way off the mark.

Know anything about launching pop-ups with php??

regards

jimw00d
January 23rd, 2003, 02:21 PM
Sorry that this question has been posted twice, I did it completely by accident.

Jubba
January 23rd, 2003, 02:39 PM
Completely all right. I took care of it for ya ;)

c0ldfusion
January 23rd, 2003, 04:21 PM
well, in case of succes, header() to .php page that says 'email sent' or something like this... otherwise, header() to a .php that says 'not sent';

furthermore, you can header() to a page like x.php?mailto=logik&browser=ie6 --i mean, transmit the parameters, and procces the $_POST parameters ( if(isset($_POST['mailto'])) echo .... )

if you want to display what the mail contained in the page you're redirecting... just put almost the same code with echo(), not with mail()


Know anything about launching pop-ups with php??

well, you can pop-up a window with javascript with the window.open() command

for further help, just let me know :)

c0ldfusion
January 23rd, 2003, 04:26 PM
and one more thing:


if (@mail($mail_to,"subject",
"browser= " . $BrowserType . "" .
"mediaTypes= " . $MediaTypes)
header("Location: http://evolt.org"));

has a syntax error:

if (CONDITION
header("Location: http://evolt.org"));

the CONDITION (@mail) is written right next to the header() command... the correct code would be:


if (@mail($mail_to,"subject",
"browser= " . $BrowserType . "" .
"mediaTypes= " . $MediaTypes))

header("Location: http://evolt.org");

jimw00d
January 23rd, 2003, 04:30 PM
I don't want to display the content of the form, I only want to display whether the form was sent to the server and processed.

Your newest addition should do the trick.

How would php launch a java pop up??

regards

jimw00d
January 23rd, 2003, 05:31 PM
The code is producing an unexpected T string error:

<html>
<body>
<?php
$ToEmail = "northls@nbkayaking.com";

$ToSubject = "Enquiry";

$BrowserType = $HTTP_USER_AGENT;

$MediaTypes = $HTTP_ACCEPT;

$ServerName= $REMOTE_ADDR;

$Date= date("d/F/y\n\nH.i");

$EmailBody = "Sent By: $FirstName\nSenders Email: $Email\n\nMessage Sent:\n$ToComments\n\n$BrowserType\n$MediaTypes\n$ ServerName\n\n$Date";

mail($ToName." <".$ToEmail.">",$ToSubject, $EmailBody, "From: ".$FirstName." <".$Email.">");

if (@mail($mail_to,"subject",
"browser= " . $BrowserType . "" .
"mediaTypes= " . $MediaTypes));

header("Location: <a href="http://evolt.org" target="_blank">http://evolt.org</a>");

?>
</body>
</html>


what is the variable $mail_to, maybe this is the problem, I don't think I named a variable in flash mail_to.

Any ideas

c0ldfusion
January 25th, 2003, 05:03 PM
if (@mail($mail_to,"subject",
"browser= " . $BrowserType . "" .
"mediaTypes= " . $MediaTypes));

has no sense...

if (CONDITION)
{
do something
}
else ....

what you've written is like:
if (CONDITION) { do nothing }

and about the $mail_to ... if you don't have any variable in flash with that name, you've obviously made a mistake... create that variable or change your code

......

about the fact that you want the user to know if your .php sent the email or not... it's very simple...

if you want to use header() as I have seen... do something like this:

if (@mail($mail_to,"subject",
"browser= " . $BrowserType . "" .
"mediaTypes= " . $MediaTypes))
header("Location: http://evolt.org/success.html");
else header("Location: http://evolt.org/fail.html");

and use the two pages success.html and fail.html

c0ldfusion
January 25th, 2003, 05:04 PM
oh, and about the popup window... check for a tutorial on the net for the javascript command window.open() ... it should explain you what you want

jimw00d
January 27th, 2003, 06:19 AM
I really do appreciate your help and feel I am close to a conclusion. Since I last posted I have decided to try and generate a php variable if the mail was sent. I have set up flash, or I am trying to at least, to receive the value of this variable.

The code is as the attachment.

What do you think.

It is generating an error on line 26, something about an extra or uneeded =

Cheers

Could I remove the echo line of the code or is this needed??

c0ldfusion
January 29th, 2003, 04:44 PM
looked over your code and corrected the syntax;

also, i must mention:



//mail($Name." <".$ToEmail.">",$ToSubject, $EmailBody, "From: ".$Name." <".$Email.">");
//don't use the mail() command twice as it will send two mails...
if(@mail(....


which i wrote you in the file...

oh, and also modified the echo() line...