php form

Status
Not open for further replies.

bunglebrown

New Member
Messages
157
Reaction score
0
Points
0
I want to put one to you that is probably glaringly obvious but bear with me. I have a simple form where users post a comment submitting their name and email address. But I can't get any of the variables to show up in the message - can anyone tell me why? ? - I'm new to it all so be gentle> lol

PHP:
<?php

// Create local PHP variables from the info the user gave in the Flash form -disabled message field
$fromname   = $_POST['fromname'];
$fromemail   = $_POST['fromemail'];
$fromcomments = $_POST['fromcomments'];

// Strip slashes on the Local variables -disabled message field
$fromname   = stripslashes($fromname);
$fromemail      = stripslashes($fromemail);
$fromcomments   = stripslashes($fromcomments); 

    $from = $fromemail;
    $subject = "my title";
    //Begin HTML Email Message
    $message = <<<EOF
<html>
  <body bgcolor="#FFFFFF">
<b>New entry<br />
<b>            $fromemail, 
<b>            <br />
<b>            $fromcomments<br />
<b>			   <a href="http://www.mywebsite.com">www.mywebsite.com</a><br />
  </body>
</html>
EOF;
   //end of message
    $headers  = "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";
    $to = "myemail@myhost.com";

    mail($to, $subject, $message, $headers);
	
exit();
?>

Edit:
no-one... no?
 
Last edited:

Nathan H

New Member
Messages
562
Reaction score
0
Points
0
EOF;

have you tried removing that?

I'll have a look in my phpIDE for you
 
Last edited:

Nathan H

New Member
Messages
562
Reaction score
0
Points
0
A quick look in my IDE has come with loads of syntax errors, a large one being
$message = <<<EOF

i'll look for a solution

I'm assuming the $fromcomments is the message you want to recieve so the modified script is below
PHP:
<?php 

// Create local PHP variables from the info the user gave in the Flash form -disabled message field 
$fromname   = $_POST['fromname']; 
$fromemail   = $_POST['fromemail']; 
$fromcomments = $_POST['fromcomments']; 

// Strip slashes on the Local variables -disabled message field 
$fromname   = stripslashes($fromname); 
$fromemail      = stripslashes($fromemail); 
$fromcomments   = stripslashes($fromcomments);  

    $from = $fromemail; 
    $subject = "my title"; 
    //Begin HTML Email Message 
    $message = $fromcomments;
    echo '
<html> 
  <body bgcolor="#FFFFFF"> 
<b>New entry<br /> </b>
<b>            '.$fromemail.',   </b>
<b>            <br />  </b>
<b>            '.$fromcomments.'<br />  </b>
<b>               <a href="http://www.mywebsite.com">www.mywebsite.com</a><br />  </b>
  </body> 
</html> 
';
   //end of message 
    $headers  = "From: $from\r\n"; 
    $headers .= "Content-type: text/html\r\n"; 
    $to = "myemail@myhost.com"; 

    mail($to, $subject, $message, $headers); 
     
exit(); 
?>

What i changed was the html section, it is now echo to the page, and removed the EOF, incase of EndOfFile conflicts, altered the sytax error from $message = <<<EOF
 
Last edited:

bunglebrown

New Member
Messages
157
Reaction score
0
Points
0
thanks for the effort with this.

Unfortunately I did try that and there was no content in the email so I am posting my flash actionscript code as well to make sure nothing is wrong there. Contact_Parse.php contains the php content previously posted (and then altered as advised).

Code:
stop();

import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
// ----------------------------------------------------------------
var variables2:URLVariables = new URLVariables();
var varSend2:URLRequest = new URLRequest("contact_parse.php");
var varLoader2:URLLoader = new URLLoader;
varSend2.method = URLRequestMethod.POST;
varSend2.data = variables;

submit2_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend2);

function ValidateAndSend2(event:MouseEvent):void{
	
    //validate form fields
	if(name2_txt.text=="Name") {
		gotoAndStop(180);
		status2_txt.text = "Please enter a name";
	} else if(!name2_txt.length) {
		gotoAndStop(180);
		status2_txt.text = "Please enter a name";
	} else if(email_addr.text=="Email Address") {
		gotoAndStop(180);
		status2_txt.text = "Please enter an email address"; 
	} else if(!email_addr.length) {
		gotoAndStop(180);
		status2_txt.text = "Please enter an email address"; 
	} else if(!validateEmail2(email_addr.text)) {
		gotoAndStop(180);
		status2_txt.text = "Please enter a valid email";
	} else if(comments_txt.text=="Comments/Suggestions") {
		gotoAndStop(180);
		status2_txt.text = "Please enter a comment";
	} else if(!comments_txt.length) {
		gotoAndStop(180);
		status2_txt.text = "Please enter a comment";
	} else {
	
  		variables2.fromname = name2_txt.text;
   		variables2.fromemail = email_addr.text;
		variables2.fromcomments = comments_txt.text;
   		varLoader2.load(varSend2);
		
		gotoAndPlay(180);
		
	}
}

function validateEmail2(str:String):Boolean {
	var pattern:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
	var result:Object = pattern.exec(str);
	if(result == null) {
		return false;
	}
	return true;
}
 

bunglebrown

New Member
Messages
157
Reaction score
0
Points
0
well I have since tried with a simple html form and it was all fine so I really think it must be the flash - what can I do to corner the exact problem and rectify it?
 

Nathan H

New Member
Messages
562
Reaction score
0
Points
0
rather than using POST statements have you tried using get
ie
URLRequest("contact_parse.php?fromname="&name2_txt.text&"&fromemail="&email_txt.text&"&fromcomments="&comments_txt.text)
 

bunglebrown

New Member
Messages
157
Reaction score
0
Points
0
not really - the not knowing how to do it made it quite difficult but do you think that could work? and what should I change?
Edit:
I just want to alert you that the problem was in the actionscript with this line:

Code:
varSend2.data = variables;

which should have been:

Code:
varSend2.data = variables2;

The PHP form from NathanH was useful although I altered the $message to include all of the variables. Thanks for that and to all who contributed as always.
 
Last edited:

Nathan H

New Member
Messages
562
Reaction score
0
Points
0
Your welcome, I'm closing this thread, if there are any other difficulties you may reopen this thread or start a new one
 
Status
Not open for further replies.
Top