PDA

View Full Version : PHP Form Submit Confusion


lightmode
03-03-2004, 08:03 PM
OK, I have collected a few pieces from here and there and I got this thing working fine on my server however when I posted to the clients server some features work and some don't. My actionscript looks like this on the "submit" button:


on (release) {
if (name_txt.text eq "" or phone_txt.text eq "" or email_txt.text eq "") {
stop();
} else {
lineAdapt();
mailVars = new LoadVars();
mailResults = new LoadVars();
mailResults.onLoad = function() {
if (this.status == "mailSent") {
gotoAndStop("Quick App",2); // Thank You page
} else {

}
};
mailVars.subject = title_txt.text + name_txt.text;
mailVars.message = unescape("Name: " + name_txt.text + " Phone: " + phone_txt.text + "Email: " + email_txt.text + " Flat or Townhouse: " + flat_txt.text + " Group Size: " + group_txt.text + " Questions: " + question_txt.text);
mailVars.from = email_txt.text;
mailVars.sendAndLoad("http://www.irvingcommons.com/mail.php", mailResults, "GET");

}
}





and the PHP file looks like this:
#!/usr/local/bin/php4
<?php
if (isset($_GET['subject'])) $message = $_GET['subject']; // checks if subject was sent in the url via GET.
// if so, it assigns that to our variable $subject
else die('&status=noSubject&'); // if not it stops the script and echos back our status message
if (isset($_GET['message'])) $message = $_GET['message'];
else die('&status=noMessage&'); // same as above
// Will have died or exited out of the script already, if we didn't have our subject and message.
mail("info@myurl.com", $subject, $message, "From: PHPMailer@irvingcommons.com\nReply-To: $from\nX-Mailer: PHP/" . phpversion());
//send information to Irving
mail($from, $subject, $message, "From: info@myurl.com\nReply-To: info@myurl.com\nX-Mailer: PHP/" . phpversion());
//send information of a new kind to Applicant
// send our mail
// change to your info - I changed to fake stuff to prevent spambots spidering this forum from getting your address
echo '&status=mailSent&'; // send back our status so our flash file knows things went okay.
?>

Here is the list of problems:
• Applicant recieves no email
• First line of MaiL() send no Subject _ should pull variables from Flash and doesn't
• Reply-To fills in with PHPMailer not the $from that it should

I am completely perplexed by this, like I said earlier the darn thing worked seemlessly on my hosting server, and when I posted it to the clients IP address,

Blam - - El, Problemo...:eek:

splict
03-03-2004, 08:44 PM
Hmmm, some of that code looks familiar ;) Actually, I'm writing a nice tutorial for this but that will probably be tommorrow or the next day.

First, you need to uncheck "Automayically parse urls's" when you post code like that - it screws stuff up. Could you fix that in your post please so we can see things properly?

Second, Nowhere in your php file do you specify what $from is, so how would the second mail() function know who to send it too? (Older versions of php may have gotten it with globals turned on, but they aren't (and shouldn't be) by default, now. (First and Third bullet point)

Third, your first line where you get the subject, you are actually assigning it to $message instead of $subject, like it should be. (Second bullet point)

Typo's brought to you by the letters 'C' and 'V'. :rolleyes: :D

That should get you started.

-splict

lightmode
03-03-2004, 09:14 PM
I thought the $from was being defined in the Actionscript like all of the other variables that are sent to mail.php ...

Yes you recognize the script because I borrowed the PHP from some help you were giving another person the other day. The weird thing is this worked fine more than once when I was beta testing and then when I moved it all to its final resting place it doesn't.

I define the $Subject by adding the title_txt.text which is the instance of the header (dynamic text) in Flash for that page, (+) name_txt.text from the first line of the form so that the client gets an email from PHP Mailer with a subject of -- Quick App: "Person Sending"---- I set this up and sent myself a ton of emails testing it. Now I put in the new emails and directives and it seems to go kaputt.


The site I am developing is www.irvingcommons.com if you want to see it in action...

splict
03-03-2004, 09:36 PM
The point is, you need to take a minute and read the reasons I spoke of - they will fix your problems. You say that you defined from in flash? Well, you did. But you didn't define it in php which is where you are using the mail function. Do you see the lines that have $_GET in them? they are transfering the variable from the info recieved from flash into local variables in the php file. You do not have one of those for your from field.

What I would recomend is that you go through that php file and read all of the comments (thats why I take so much time to put them in there). I'm sure you have read them, but I mean to reread them and refer to the php manual at php.net (it is one of the best manuals in existence IMO) as you are doing so. This way you will better understand what each line does and you will understand what I mean when I am explaining your problem. That, combined with fixing the subject/message typo I previously refered to, should get you much further along.

BTW, I think that there was a later post in that thread, that had the code fixed up on it, I will check, and if I haven't yet, then I will fix it. My apologies for any bad code I write - my footer is certainly sarcastic ;)

Please post more questions as you have them, I am just pointing out that referencing the manual at the same time will give you an understanding of why you are doing what you are doing - then you can better troubleshoot, yourself :) Let me know how it goes.

-splict

lightmode
03-03-2004, 09:53 PM
How bout this?

#!/usr/local/bin/php4
<?php
if (isset($_GET['subject'])) $subject = $_GET['subject'];
// checks if subject was sent in the url via GET.
// if so, it assigns that to our variable $subject
else die('&status=noSubject&');
// if not it stops the script and echos back our status message
if (isset($_GET['message'])) $message = $_GET['message'];
else die('&status=noMessage&');
// if not it stops the script and echos back our status message
if (isset($_GET['from'])) $from = $_GET['from'];
else die('&status=noFrom&'); // same as above
// Will have died or exited out of the script already, if we didn't have our subject and message.
mail("info@irvingcommons.com", $subject, $message, "From: PHPMailer@irvingcommons.com\nReply-To: $from\nX-Mailer: PHP/" . phpversion());
//send information to Irving
mail($from, $subject, $message, "From: PHPMailer@irvingcommons.com\nReply-To: info@irvingcommons.com\nX-Mailer: PHP/" . phpversion());
//send information of a new kind to Applicant
echo '&status=mailSent&'; // send back our status so our flash file knows things went okay.
?>

splict
03-03-2004, 09:58 PM
could you redo the post with the php tags and uncheck Automatically parse URL's like I previously mentioned, please?

lightmode
03-03-2004, 09:59 PM
One damn word in the wrong place and the whole thing goes to hell in a handbasket...

I fixed the typo and added a condition for from and BLAM - El Productivo

splict
03-03-2004, 09:59 PM
great :)

lightmode
03-03-2004, 10:02 PM
You are so responsive. Stern, yet educational....