Hi, I would like some help please. I have made a contact form on Flash and called on a PHP file to send the form through mail. When I receive the e-mail, it is all messed up with HTML tags of the text formatting everywhere... Even in the "From" and "Subject" part.. Can anybody help me take the formatting off? Is a very simple PHP action, below you will find the flash actionscript (very simple) and the PHP script I am using. Please help!! :)

Here is the example of the mail I am receiving:

Name:<TEXTFORMAT LEADING=\"2\"><P ALIGN=\"LEFT\"><FONT FACE=\"_sans\" SIZE=\"12\" COLOR=\"#000000\" LETTERSPACING=\"0\" KERNING=\"0\">John Smith</FONT></P></TEXTFORMAT> E-mail <TEXTFORMAT LEADING=\"2\"><P ALIGN=\"LEFT\"><FONT FACE=\"_sans\" SIZE=\"12\" COLOR=\"#000000\" LETTERSPACING=\"0\" KERNING=\"0\">ldskjflk</FONT></P></TEXTFORMAT>
Address: <TEXTFORMAT LEADING=\"2\"><P ALIGN=\"LEFT\"><FONT FACE=\"_sans\" SIZE=\"12\" COLOR=\"#000000\" LETTERSPACING=\"0\" KERNING=\"0\">jlkjlkj</FONT></P></TEXTFORMAT>
Message: <TEXTFORMAT LEADING=\"2\"><P ALIGN=\"LEFT\"><FONT FACE=\"Arial\" SIZE=\"12\" COLOR=\"#000000\" LETTERSPACING=\"0\" KERNING=\"0\">lkjlkjlkj</FONT></P></TEXTFORMAT>

here is the actionscript from flash:

sendBtn.onRelease = function() {
    form.loadVariables("email1.php", "POST");

and here is the PHP script I am using:

$sendTo = 'info@bhbmarketingsolutions.com';
$subject = 'Contact from BHB Marketing Solutions Web Page';
$message = "Nombre: $nombre
E-mail $email
Dirección: $direccion
Telefono: $telefono
Codigo Postal: $cp
Pais: $pais
Provincia: $provincia
Comentario: $mess";

$headers = 'From: ' . $_POST['nombre'];
mail($sendTo, $subject, $message, $headers);

I think it may probably be a Flash issue?? or can this be done through PHP?

I read a post in this forum from months ago with kind of the same problem, but the problem wasn't solved. Here is the link of the other post:


And the solution seems to be quite simple.. I tried to do this, but instead of receiving an HTML message, I receive all the HTML tags of the suppossed "HTML" message.

Can someone help me? :)

Recommended Answers

All 5 Replies

you need the send the content-type header with the script so it will be displayed as html not text.


$headers = 'From: ' . $_POST['nombre'];


$headers  = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";

Thanks alot, you really fixed all the problem, however I have just a little problem still... All the message of the mail is displayed great, as HTML and everything is good. Now the only problem is the "From" part of the mail it keeps on displaying the HTML code. So, the subject is ok, the message is ok, put the "from" keeps on displaying the tags... any ideas?

Thank you very much for your help, it was really useful :)

Hi, sense you're using AS 2.0, i may consider the use of the sendAndLoad function, and make your PHP return something like a boolean flag, so on the cliente side (flash) you can tell the user either the mail was sent successfully or not.

You can add an eventListner on the flash side that listens for a php reply, and checks either is TRUE ou FALSE, so you can show the user an acurate message.

But, going from you're now, why is the flash passing all that HTML? can't you pass only the values you need and then paste them on the PHP along with the HTML?

That will solve you problems about the HTML entities and tags.
Will help you satitaze your data, either on the flash side, to make sure the data you're sending to the php is in real what you whant it to be.
And will help you validate that data on the server side (you can never trust the user allways validate you data).
And finaly the amount of data being trade from client to server and backwords will be a lot less, so you will save bandwith.

Well.. as you can see I am using a very easy flash form to send the information to my e-mail. I am using the following:


So that when the data is sent, the user may receive a notification message that the data has been sent.

However, I am reading about the sendAndLoad function, and I tried to make it work, but to tell you the truth I am not that good Action sript programmer, so I have to get into Actionscript more so that I know how exactly that works. And adding an eventListner would be helpful, unfortunately I don't know exactly how that works.

As for the HTML I already figured out why the message came with all the HTML tags in the message and already have been able to fix it. But It would be really helpful if you could assist me in the flash part of the boolean flag, eventListener, and sendAndLoad...

I could easily send you the files over mail or something and you can help me with that? Please let me know... I really appreciate it.

ok, lets do what good programmers do and devide the problem, my english is not very good but i'll try my best, to make you understand.

Lets start with the most important thing that is getting confirmation from the PHP into our flash movie, using the sendAndLoad object.

Ok first of all in order to use the sendAndLoad you'll need 2 loadVars objects, one for getting the data to be sent and the other one that will store the data PHP gives back.

The code to do this may become a little extensive, so i recomend using a function to store this methods and the comunication, this way it will be easyer to debug later.

So here's the code:

// Lets create a function
function sendEmail():Void
	// lets create the object to store the data to be sent.
	var sendData = new LoadVars();
	// ok now lets fill this object with the actual data
	// in order to do this you simply add a dot and the name you will use 
	// in the POST index. For example sendData.Message = "abc" you will be able to catch
	// the value in PHP like echo $_POST['Message']; that will output: abc
	sendData.Name = _root.form.Name.text;
	sendData.Message = _root.form.Message.text;
	// so on...  add as much elements as the fields you what to send.
	// ok now we need the object to store the data PHP will give you back
	var getData = new LoadVars();
	// ok now we have data to send and an object to store the reply.
	// lets see the sendAndLoad method:
	// this method requires 3 parameters in the order URL, TargetObject, Method
	// URL is the name and path of the PHP file you're calling for example "include/form.php"
	// or simply form.php if the PHP file is in the sabe directory of the flash movie
	// targetObject is the object that will hold the reply data in our case the getData var we created
	// Method is the method to be used to send the data so in this case it will be POST
	sendData.sendAndLoad("url.php", getData, "POST");
	// ok so we collected the data and have send it to PHP now we need the reply
	// so lets use the eventListenner that we have in LoadVars called onLoad and 
	// make something with that data.
	getData.onLoad = function(success:Boolean){
		// ok function is created, but see that i require a boolean value
		// in order to know if the flash loaded some Data, if so we will process that data
		// otherwise store a message in a msg var
			// ok by this point we have data to show, now lets see if we got errors
			// if we do we add the errors to a var so we can deal with it later if we don't,
			// we will store the message returned by PHP into an msg var.
				// store the error on a variable
				var error = getData.Errors;
				// call a function that will deal with your error, and pass the error var as a parameter
				//store the message in a msg var
				msg = getData.Msg;
				// tell root to go to the next frame
			// store the connection error in a msg
			msg = "Connection error: unable to contact the server";
			// tell root to go to the next frame

OK so in the frame the clip will jump to create a dynamic text field and under the properties tab you've got a a box called "var" this is use to associate a dynamic text field with a variable, every time the value of the variable changes so the text field. so in this case give "msg" as name the text field var, so it will display the message.

In the php if the email is sent without problems make an echo of the success message like:

 echo "&msg= your message";

or you create an error description to deal on flash side like

 echo "&error= your error message";

let me know if you get this so far and if it helps.

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.