Hi Everyone,
Another newby here with hat in hand. I'm working on a basic flash/php mail program. Working with the template provide from a website; I want some additional fields to the formmail. So I added some text boxes to the .FLA file which sends the variables to the PHP file.

I thought it would be simple enough to do, but I'm still not getting the output I want; showing all the text fields in the email.

This is the actionscript for the .FLA file

stop();

name_box.tabIndex = 1;
phone_box.tabIndex = 2;
subject_box.tabIndex = 3;
email_box.tabIndex = 4;
street_box.tabIndex = 5;
po_box.tabIndex = 6;
city_box.tabIndex = 7;
state_box.tabIndex = 8;
zip_box.tabIndex = 9;
ccomments_box.tabIndex = 10;

send_btn.onRelease = function() {
	my_vars = new LoadVars();
	my_vars.cname = name_box.text;
	my_vars.cphone = phone_box.text;
	my_vars.csubject = subject_box.text;
	my_vars.csender = email_box.text;
	my_vars.cstreet = street_box.text;
	my_vars.cpo = po_box.text;
	my_vars.ccity = city_box.text;
	my_vars.cstate = state_box.text;
	my_vars.czip = zip_box.text;
	my_vars.ccomments = ccomments_box.text;
	if (my_vars.csender != "" and my_vars.csubject != "" and my_vars.ccomments != ""and my_vars.cstate != "" and my_vars.czip != "") {
		my_vars.sendAndLoad("mailer.php", my_vars, "POST");
		gotoAndStop("success");
	} else {
		error_clip.gotoAndPlay("success");
	}
	my_vars.onLoad = function() {
		gotoAndStop("fail");
	};
};
email_box.onSetFocus=csubject_box.onSetFocus=cmessage_box.onSetFocus=function () {
	if (error_clip._currentframe != 1) {
		error_clip.gotoAndPlay(6);
	}
};
/*email_box.onSetFocus = subject_box.onSetFocus=message_box.onSetFocus=function () {
	if (error_clip._currentframe != 1) {
		error_clip.gotoAndPlay(6);
	}
};
*/

and this is the code on the php side

<?php
/* ---------------------------
php and flash contact form.
by www.MacromediaHelp.com
---------------------------
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).
$csubject = $_REQUEST["subject"];
$cname = $_REQUEST["name"];
$cphone = $_REQUEST["phone"];
$cstreet = $_REQUEST["street"];
$cpo = $_REQUEST["po"];
$ccity = $_REQUEST["city"];
$cstate = $_REQUEST["state"];
$czip = $_REQUEST["zip"];
$ccomments = $_REQUEST["ccomments"];
$csender = $_REQUEST["sender"];

// include sender IP in the message.
$full_message = $_SERVER['REMOTE_ADDR'] . "\n\n" . $ccomments . "\n\n" . $cname . "\n\n" . $cphone . "\n\n" . $cstreet . "\n\n" . $cpo . "\n\n" . $ccity . "\n\n" . $cstate . "\n\n" . $czip;
$message= $full_message;
// remove the backslashes that normally appears when entering " or '
$message = stripslashes($message);
$subject = stripslashes($csubject);
$sender = stripslashes($csender);



// 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) and isset($sender)){
mail("administrator@gnci.net", $subject, $message, "From: $sender");
}
?>

and this is the email that I get
------------------------------------------------------
Sent: Tuesday, October 30, 2007 2:10 AM
To: Administrator
Subject: Contact form

comments3
--------------------------------------------------

Dani AI

Generated

Short diagnosis and a safe quick fix: the form fields that arrive in PHP must use the same names Flash sends. If Flash is posting names with a leading c (for example cname, csubject, csender), PHP needs to read those exact keys (or Flash must be changed to post without the c prefix). Prefer reading POST explicitly and trim inputs so empty strings are obvious during debugging. Example (use this as a replacement for fragile direct reads):

$cname    = isset($_POST['cname'])    ? trim($_POST['cname'])    : '';
$csubject = isset($_POST['csubject']) ? trim($_POST['csubject']) : '';
$csender  = isset($_POST['csender'])  ? trim($_POST['csender'])  : '';
$ccomments= isset($_POST['ccomments'])? trim($_POST['ccomments']): '';

This keeps names aligned with what Flash sends and avoids surprises from cookies/GET mixing. (php.net)

ActionScript gotcha to watch: assign the LoadVars onLoad handler before you call sendAndLoad, and do not jump frames immediately after issuing the request. If the movie changes frames (or unloads the clip) before the server responds the callback may never run. Move frame-switching into the onLoad callback and inspect the boolean success to decide whether to show success or failure. (open-flash.github.io)

About 's single-quote suggestion: single quotes in PHP do not expand variables; they produce literal text. Use concatenation or double-quoted strings when you need variable interpolation. Also validate and sanitize any user-supplied email before putting it into headers (strip CR/LF to avoid header injection, and use filter_var(..., FILTER_VALIDATE_EMAIL)); set a site-owned From and use Reply-To for the user email if the host requires an internal sender. Examples shown above are minimal; treat headers and mail() use carefully (mail() expects CRLF and has hosting caveats). (php.net)

Quick debugging checklist:

  • Log the whole request server-side (eg. error_log(var_export($_POST, true));) to verify names/values.
  • Return a small urlencoded status (like status=ok) from PHP so Flash LoadVars can read it.
  • Check mail() return value and hosting/sendmail_from settings if mail never arrives.
  • Sanitize inputs to prevent header injection and prefer a tested mailer library (PHPMailer/SwiftMailer) for production. (php.net)

If desired, post the exact names Flash is sending and the current PHP reads and someone will give a copy-paste-ready corrected snippet tied to your SWF.

Recommended Answers

All 2 Replies

try placing the variables in single quotes like this:

$full_message = $_SERVER . "\n\n" . '$ccomments '. "\n\n" . '$cname' . "\n\n" . '$cphone' . "\n\n" . '$cstreet' . "\n\n" . '$cpo' . "\n\n" . '$ccity' . "\n\n" . '$cstate' . "\n\n" .' $czip'

Member Avatar for Member #210412

i added the full code, check it over... and checks smtp server also

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.