Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email form in flash to php help?

Status
Not open for further replies.

fizzak

MIS
Feb 6, 2003
331
US
I'm having some trouble with this code, not sure if I need a Flash expert though. I grabbed a tutorial from
This is to show you how to add a form to a Flash site that allows visitors to email you.
Ive tried the sample files on my hosting and it works fine. However if I add the code to my flash site with an additional $name field, but it doesn't work. Perhaps a PHP expert can spot my mistake?

The ActionScript______________
stop();
System.useCodepage = true;
send_btn.onRelease = function() {
my_vars = new LoadVars();
my_vars.sender = email_box.text;
my_vars.name = name_box.text;
my_vars.subject = subject_box.text;
my_vars.message = message_box.text;
if (my_vars.sender != "" and my_vars.name != "" and my_vars.subject != "" and my_vars.message != "") {
my_vars.sendAndLoad("mailer.php",my_vars,"POST");
gotoAndStop(2);
} else {
error_clip.gotoAndPlay(2);
}
my_vars.onLoad = function() {
gotoAndStop(3);
};
};
email_box.onSetFocus = name_box.onSetFocus=subject_box.onSetFocus=message_box.onSetFocus=function () { if (error_clip._currentframe != 1) {error_clip.gotoAndPlay(6);}
};;

The php___________________

<?php

/* ---------------------------
php and flash contact form.
by ---------------------------
Note: most servers require that one of the emails (sender or receiver) to be an email hosted by same server,
so make sure your email (on last line of this file) is one hosted on same server.
--------------------------- */


// read the variables form the string, (this is not needed with some servers).
$subject = $_REQUEST["subject"];
$name = $_REQUEST["name"];
$message = $_REQUEST["message"];
$sender = $_REQUEST["sender"];


// include sender IP in the message.
$full_message = $_SERVER['REMOTE_ADDR'] . "\n\n" . $message;
$message= $full_message;

// remove the backslashes that normally appears when entering " or '
$message = stripslashes($message);
$subject = stripslashes($subject);
$name = stripslashes($name);
$sender = stripslashes($sender);

// add a prefix in the subject line so that you know the email was sent by online form
$subject = "Contact form ". $subject;

// send the email, make sure you replace email@yourserver.com with your email address
if(isset($message) and isset($subject) isset($name) and isset($sender)){
mail("fizzak2@mydomain.com", $subject, $name, $message, "From: $sender");
}
?>
 
the problem is in the last section. change this line
Code:
if(isset($message) and isset($subject) isset($name) and isset($sender)){

to
Code:
if(!empty($message) && !empty($subject) && !empty($name) && !empty($sender)){
 
However if I add the code to my flash site with an additional $name field, but it doesn't work.

Kind if vague. "Doesn't work" how? Do you get an error? Is the email not sent? Does the name not get sent in the email?


Anyway, for starters here:

Code:
if(isset($message) and isset($subject) isset($name) and isset($sender)){
...

you are missing an "AND" between isset($subject) and isset($name)


Then here:

Code:
 mail("fizzak2@mydomain.com", $subject, $name, $message, "From: $sender");
[code]

The mail function takes 4 basic parameters:

TO: Who you want the ail sent to
SUBJECT: what the subject line of the email should say.
MESSAGE: the actual message of the email
HEADERS: additional headers such as who the email is from, email address to reply to etc..

With that said, your $name variable either needs to be included in the $message or in $headers depending on where you want it to appear. 

But it cannot be sent as a stand alone variable, because then $name becomes the body of your message. And the rest of the variables are taken as something else in the mail function. 













----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
<blockquote>Kind if vague. "Doesn't work" how? Do you get an error? Is the email not sent? Does the name not get sent in the email?</blockquote>

Yes, the email never gets sent. No error, nothing. I did notice the "and" missing and replaced it but no go. I'm assuming with what you said, even if the information does not get organized perfectly, the email should send as it does with the original sample files I copied the code from?

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top