Contact form Flash/PHP sends with Text Formatting

Reply

Join Date: Mar 2008
Posts: 3
Reputation: mav140 is an unknown quantity at this point 
Solved Threads: 0
mav140 mav140 is offline Offline
Newbie Poster

Contact form Flash/PHP sends with Text Formatting

 
0
  #1
Mar 3rd, 2008
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:

stop();
sendBtn.onRelease = function() {
formText._visible=false;
form.loadVariables("email1.php", "POST");
}

and here is the PHP script I am using:

<?php
$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:

http://www.daniweb.com/forums/thread90716.html

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?
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Contact form Flash/PHP sends with Text Formatting

 
0
  #2
Mar 3rd, 2008
you need the send the content-type header with the script so it will be displayed as html not text.

replace:

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

with:

  1. $headers = "From: $from\r\n";
  2. $headers .= "Content-type: text/html\r\n";
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 3
Reputation: mav140 is an unknown quantity at this point 
Solved Threads: 0
mav140 mav140 is offline Offline
Newbie Poster

Re: Contact form Flash/PHP sends with Text Formatting

 
0
  #3
Mar 4th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 7
Reputation: miguelp is an unknown quantity at this point 
Solved Threads: 0
miguelp miguelp is offline Offline
Newbie Poster

Re: Contact form Flash/PHP sends with Text Formatting

 
0
  #4
Mar 4th, 2008
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.
Last edited by miguelp; Mar 4th, 2008 at 5:46 am.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 3
Reputation: mav140 is an unknown quantity at this point 
Solved Threads: 0
mav140 mav140 is offline Offline
Newbie Poster

Re: Contact form Flash/PHP sends with Text Formatting

 
0
  #5
Mar 4th, 2008
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:

onClipEvent(data){
_root.nextFrame();
}

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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 7
Reputation: miguelp is an unknown quantity at this point 
Solved Threads: 0
miguelp miguelp is offline Offline
Newbie Poster

Re: Contact form Flash/PHP sends with Text Formatting

 
0
  #6
Mar 5th, 2008
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:
Actionscript Syntax (Toggle Plain Text)
  1. // Lets create a function
  2. function sendEmail():Void
  3. {
  4. // lets create the object to store the data to be sent.
  5. var sendData = new LoadVars();
  6. // ok now lets fill this object with the actual data
  7. // in order to do this you simply add a dot and the name you will use
  8. // in the POST index. For example sendData.Message = "abc" you will be able to catch
  9. // the value in PHP like echo $_POST['Message']; that will output: abc
  10. sendData.Name = _root.form.Name.text;
  11. sendData.Message = _root.form.Message.text;
  12. // so on... add as much elements as the fields you what to send.
  13. // ok now we need the object to store the data PHP will give you back
  14. var getData = new LoadVars();
  15. // ok now we have data to send and an object to store the reply.
  16. // lets see the sendAndLoad method:
  17. // this method requires 3 parameters in the order URL, TargetObject, Method
  18. // URL is the name and path of the PHP file you're calling for example "include/form.php"
  19. // or simply form.php if the PHP file is in the sabe directory of the flash movie
  20. // targetObject is the object that will hold the reply data in our case the getData var we created
  21. // Method is the method to be used to send the data so in this case it will be POST
  22. sendData.sendAndLoad("url.php", getData, "POST");
  23. // ok so we collected the data and have send it to PHP now we need the reply
  24. // so lets use the eventListenner that we have in LoadVars called onLoad and
  25. // make something with that data.
  26. getData.onLoad = function(success:Boolean){
  27. // ok function is created, but see that i require a boolean value
  28. // in order to know if the flash loaded some Data, if so we will process that data
  29. // otherwise store a message in a msg var
  30. if(success){
  31. // ok by this point we have data to show, now lets see if we got errors
  32. // if we do we add the errors to a var so we can deal with it later if we don't,
  33. // we will store the message returned by PHP into an msg var.
  34. if(getData.Errors){
  35. // store the error on a variable
  36. var error = getData.Errors;
  37. // call a function that will deal with your error, and pass the error var as a parameter
  38. _root.dealWithError(error);
  39. }else{
  40. //store the message in a msg var
  41. msg = getData.Msg;
  42. // tell root to go to the next frame
  43. _root.nextFrame();
  44. }
  45. }else{
  46. // store the connection error in a msg
  47. msg = "Connection error: unable to contact the server";
  48. // tell root to go to the next frame
  49. _root.nextFrame();
  50. }
  51. }
  52. }

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:
  1. <?php
  2. echo "&msg= your message";
  3. ?>

or you create an error description to deal on flash side like
  1. <?php
  2. echo "&error= your error message";
  3. ?>

let me know if you get this so far and if it helps.
Last edited by miguelp; Mar 5th, 2008 at 8:55 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC