| 1. |
Solve : Form submission - little thing? |
|
Answer» Hi guys.. i've made a form and am trying to get it to send it to my email.. Put this in the third line in form.php: print "$fname";No lol. yeah it seems like i need a body i'll try that page thanks.i tried this: Code: [Select]<?php $fname=$_POST['firstname'];/*thislineistextfieldname*/ print"$fname"; //Declaratethenecessaryvariables $mail_to="[emailprotected]"; $mail_from="[emailprotected]"; $mail_sub="FormData"; $body="Hi,\n\nHowareyou?"; $mail_mesg=$fname; //Checkforsuccess/failureofdelivery if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from")) echo"<spanclass='textred'>YourApplicationhasbeensentsuccessfully!Wewillgetbacktoyouwithin24hours.Regards,Psy.</span>"; else echo"<spanclass='textred'>Failedtosendyourapplication!<br>Thiswaseithercausedby•aninternetfault,inwhichcase,tryagain.or•Wearecarryingoutmaintenancework,inwhichcase,pleasetryagainlater.Thankyou.</span>"; ?> but it didn't work! it was basically copied from the site lol.. i also tried it with the $body = "Hi,\n\nHow are you?"; replaced as $mail_body ="Hi,\n\nHow are you?" but no lolright if i enter this: Code: [Select]<?php $fname=$_POST['Name']; //Declaratethenecessaryvariables $mail_to="[emailprotected]"; $mail_from="[emailprotected]"; $mail_sub="Enquiry"; $mail_mesg="hihowareyou"; //Checkforsuccess/failureofdelivery if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from")) echo"<spanclass='textred'>YourApplicationhasbeensentsuccessfully!Wewillgetbacktoyouwithin24hours.Regards,Psy.</span>"; else echo"<spanclass='textred'>Failedtosendyourapplication!<br>Thiswaseithercausedby•aninternetfault,inwhichcase,tryagain.or•Wearecarryingoutmaintenancework,inwhichcase,pleasetryagainlater.Thankyou.</span>"; ?> i get the message "Hi, how are you" naturally.. so where it says "mail_mesg=" i need something that will collect the data that was entered into the forms I decided to check out the code on my xampp server and found out the obvious. In your html form, you don't have any names for your text boxes! Name your text boxes and try it again.nope still blank lolmake sure you're calling the same variable in your php file. If you named your text box "Name", then make sure you call it with $_POST['Name']; that worked. cheers guys!TWO things: The proper way to do an IF statement: if(CONDITION) { statement here } else { other statement } Also, using quotes. Instead of double quotes: echo " blah blah blah"; use single quotes: echo 'blah blah blah'; EXCEPT!! when you echo a variable. If you want to echo a line that has a variable in it, than you use double quotes. echo "$variable"; Quote from: Astoria on December 12, 2007, 11:38:04 PM Two things: Have you ever done any programming at all? There's several ways to set up an if statement. You don't need the curly brackets for a one line if, else, for, or while, and it doesn't matter how it's formatted. every interpreter and compiler ignores white space anyway. Quotes don't matter either! Besides, the original poster already resolved his problem, why'd you bring it back up? Quote from: michaewlewis on December 13, 2007, 01:17:52 PM Quote from: Astoria on December 12, 2007, 11:38:04 PMTwo things: I was trying to help... It's a bad habit not to do your if/else staements without curly brackets, THAT'S WHY I brought it back up. And FYI, yes I've done tons of programming, and from what I've seen, quotes have cause ppl's lots of headaches. And in the scripts that he posted, he didn't resolve my tips.It's a bad habit to think that everyone has to conform to your own coding style. The guy wasn't trying to make his code look pretty, he was trying to fix his code. Your comments didn't help him solve anything. Quote from: michaewlewis on December 14, 2007, 10:57:46 AM It's a bad habit to think that everyone has to conform to your own coding style. No, you're wrong. It's a bad habit to code scripts in a way that can lead to many mistakes. I'm not trying to force my coding on anyone, and his problems were already solved when I made that post. All I am trying to say is that it's better to be safe than sorry. But apparently that's not ALLOWED on this forum...at least in your opinion. |
|