social Posted April 23, 2009 Share Posted April 23, 2009 Hi everyone! I AM HAVING MAJOR TROUBLE AND REALLY NEED SOME HELP. I HAVE A FORM THAT ALLOWS THE USER TO CLICK AND BUTTON TO BECOME A FAN OF A BUSINESS. WHEN THE BUTTON IS CLICKED, THE INFORMATION ABOUT THE USER IN SENT TO THE DATABASE AND AN EMAIL IS SENT TO THE BUSINESS SAYING THAT THEY HAVE A NEW FAN. THE PROBLEM IS WHEN I INCLUDED THE CODE: (isset($_POST['yourfan'])) TO CHECK IF THE BUTTON WAS CLICKED, THE FORM DOES NOT SEND THE EMAIL TO THE BUSINESS BUT WHEN I REMOVE THAT CODE, AN EMAIL IS SENT TO THE BUSINESS WHETHER OR NOT THE BUTTON IS PRESSED. WHAT DO I DO? I ONLY WANT THE EMAIL SENT WHEN THE IS BUTTON CLICKED. THE FULL CODE IS BELOW, PLEASE HELP!!! ???: <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="fan" id="fan"> <input name="yourfan" type="image" value="Submit" onClick="<?php (isset($_POST['yourfan'])) { $to = $row_Bus['Email']; $subject = 'You Have A Fan !'; $body = "blah...blah...blah.... "; $headers = "From: admin@mysite.com\r\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1 \n"; $mail_sent = @mail( $to, $subject, $body, $headers ); } ?>;MM_popupMsg('It\'s official! You are now a fan.')" src="/FANBUT2.png" alt="Become A Fan"/> </label> <input type="hidden" name="MM_insert" value="fan" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/155389-php-email-problem-and-submit-button/ Share on other sites More sharing options...
mikesta707 Posted April 23, 2009 Share Posted April 23, 2009 change (isset($_POST['yourfan'])) to if (isset($_POST['yourfan'])) also please dont write in all caps... ever Quote Link to comment https://forums.phpfreaks.com/topic/155389-php-email-problem-and-submit-button/#findComment-817584 Share on other sites More sharing options...
social Posted April 23, 2009 Author Share Posted April 23, 2009 I am sorry....I forgot to include "if"...the code actually is written as: <?php if (isset($_POST['yourfan']))..............and it still does not work. Please help ??? Quote Link to comment https://forums.phpfreaks.com/topic/155389-php-email-problem-and-submit-button/#findComment-817601 Share on other sites More sharing options...
mikesta707 Posted April 23, 2009 Share Posted April 23, 2009 Oh ok. well the thing is that the post variable yourfan won't become set unless you.. well.. post the form itself. When the page itself is loaded, the variable $_POST['yourfan'] isn't set, and unless you submit the form to the page again, it won't become set. What i would do, instead of having PHP execute with the onclick event, just set the action to a certain page (like mail.php or something) and put the code you had after onclick in that page. Quote Link to comment https://forums.phpfreaks.com/topic/155389-php-email-problem-and-submit-button/#findComment-817607 Share on other sites More sharing options...
social Posted April 23, 2009 Author Share Posted April 23, 2009 Okay, great, I will try that and see what happens...thanks! Quote Link to comment https://forums.phpfreaks.com/topic/155389-php-email-problem-and-submit-button/#findComment-817633 Share on other sites More sharing options...
kenrbnsn Posted April 23, 2009 Share Posted April 23, 2009 Remove the 'enctype="multipart/form-data" ' from the <form> statement. Ken Quote Link to comment https://forums.phpfreaks.com/topic/155389-php-email-problem-and-submit-button/#findComment-817634 Share on other sites More sharing options...
social Posted April 23, 2009 Author Share Posted April 23, 2009 Hi, I removed the encrypt line and tried putting the code in an external file...mail.php and referred the action to mail.php and it what it did was send the email message but did not insert the information into the database. Also, it also went to a page that does not exist, eg: /mail.php/profile-2.php?BusID=xxxx I DON'T know what to do....i have been trying everything for days now and nothing works the way I need it....PLEASE HELP!! :'( Quote Link to comment https://forums.phpfreaks.com/topic/155389-php-email-problem-and-submit-button/#findComment-817852 Share on other sites More sharing options...
mikesta707 Posted April 23, 2009 Share Posted April 23, 2009 post mail.php, and please use the code tags. as far as it going to a page that doesnt exist... post the page with the html forms also. Quote Link to comment https://forums.phpfreaks.com/topic/155389-php-email-problem-and-submit-button/#findComment-817857 Share on other sites More sharing options...
social Posted April 23, 2009 Author Share Posted April 23, 2009 Okay..... the mail.php is: <body> <?php If (isset($_POST['yourfan'])) { $to = $row_Bus['Email']; $subject = 'You Have A Fan !'; $body = "blah...blah...blah.... "; $headers = "From: admin@mysite.com\r\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1 \n"; $mail_sent = @mail( $to, $subject, $body, $headers ); } ?>;MM_popupMsg('It\'s official! You are now a fan.')" src="/FANBUT2.png" alt="Become A Fan"/> </label> <input type="hidden" name="MM_insert" value="fan" /> </body> </html> THE FORM CODE IS: //INSERT FAN--------------------------------------------------------------------------------------------- if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "fan")) { $Fdate = date ("M. d, y"); $FANdate = $Fdate ; $insertSQL = sprintf("INSERT INTO BusFans (FanID, FanUname, FirstName, LastName, FanCity, FanState, FanBus, FanBusID, BusName, BusPict, BUsername, NumberFans, BusID, Category, Date, FanPict) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['memID'], "int"), GetSQLValueString($_POST['username'], "text"), GetSQLValueString($_POST['FirstName'], "text"), GetSQLValueString($_POST['LastName'], "text"), GetSQLValueString($_POST['FanCity'], "text"), GetSQLValueString($_POST['FanState'], "text"), GetSQLValueString($_POST['FanBus'], "text"), GetSQLValueString($_POST['FanBusID'], "text"), GetSQLValueString($_POST['BusName'], "text"), GetSQLValueString($_POST['buspict'], "text"), GetSQLValueString($_POST['buser'], "text"), GetSQLValueString($_POST['number'], "text"), GetSQLValueString($_POST['BusID'], "int"), GetSQLValueString($_POST['category'], "text"), GetSQLValueString($FANdate, "text"), GetSQLValueString($_POST['FanPict'], "text")); mysql_select_db($database_BUSPROFILES, $BUSPROFILES); $Result1 = mysql_query($insertSQL, $BUSPROFILES) or die(mysql_error()); $insertGoTo = "/busprofile-2.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } <!--START OF FORM--> <form action="mail.php<?php echo $editFormAction; ?>" method="POST" name="fan" id="fan"> <label> <input name="username" type="hidden" id="username" value="<?php echo $row_User['Username']; ?>" /> <input name="memID" type="hidden" id="memID" value="<?php echo $row_User['MemID']; ?>" /> <input name="FirstName" type="hidden" id="FirstName" value="<?php echo $row_User['FirstName']; ?>" /> <input name="LastName" type="hidden" id="LastName" value="<?php echo $row_User['LastName']; ?>" /> <input name="BusName" type="hidden" id="BusName" value="<?php echo $row_Profile['BusName']; ?>" /> <input name="BusID" type="hidden" id="BusID" value="<?php echo $row_Profile['BusID']; ?>" /> <input name="FanPict" type="hidden" id="FanPict" value="<?php echo $row_User['MemPict']; ?>" /> <input name="FanCity" type="hidden" id="FanCity" value="<?php echo $row_User['City']; ?>" /> <input name="FanState" type="hidden" id="FanState" value="<?php echo $row_User['State']; ?>" /> <input name="category" type="hidden" id="category" value="<?php echo $row_Profile['Category']; ?>" /> <input name="buspict" type="hidden" id="buspict" value="<?php echo $row_Profile['BusImage']; ?>" /> <input name="FanBusID" type="hidden" id="FanBusID" value="<?php echo $row_UserProfile['BusID']; ?>" /> <input name="FanBus" type="hidden" id="FanBus" value="<?php echo $row_UserProfile['BusName']; ?>" /> <input name="buser" type="hidden" id="buser" value="<?php echo $row_Profile['Username']; ?>" /> <input name="number" type="hidden" id="number" value="1" /> <input name="BusEmail" type="hidden" id="BusEmail" value="<?php echo $row_Profile['Email']; ?>" /> <input name="yourfan" type="image" value="Submit" onClick="MM_popupMsg('It\'s official! You are now a fan.')" src="IMAGES/FANBUT2.png" alt="Become A Fan"/> </label> <input type="hidden" name="MM_insert" value="fan" /> </form> Please note: I have also tried making the action just: action"mail.php" without the "echo $editFormAction" and it didn't work either. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/155389-php-email-problem-and-submit-button/#findComment-817878 Share on other sites More sharing options...
mikesta707 Posted April 23, 2009 Share Posted April 23, 2009 ok... first things <body> <?php If (isset($_POST['yourfan'])) { $to = $row_Bus['Email']; $subject = 'You Have A Fan !'; $body = "blah...blah...blah.... "; $headers = "From: admin@mysite.com\r\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1 \n"; $mail_sent = @mail( $to, $subject, $body, $headers ); } ?>;MM_popupMsg('It\'s official! You are now a fan.')" src="/FANBUT2.png" alt="Become A Fan"/> </label> <input type="hidden" name="MM_insert" value="fan" /> get rid of the stuff after the PHP... i dont even understand why it would still be there... based on what you have on your form page your mail page should be something like If (isset($_POST['yourfan'])) { $to = $_POST['BusEmail'];//or whatever the post variable which holds the target email $subject = 'You Have A Fan !'; $body = "blah...blah...blah.... "; $headers = "From: admin@mysite.com\r\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1 \n"; $mail_sent = @mail( $to, $subject, $body, $headers ); } ?> As far as the action... i dont even understand where the variable you are using is coming from. I would really suggest you learn a lot more about PHP before continuing with this project, as from what i've seen it doesnt seem like you understand it very well (no offense) let me know if that helps. I hope it does Quote Link to comment https://forums.phpfreaks.com/topic/155389-php-email-problem-and-submit-button/#findComment-817890 Share on other sites More sharing options...
social Posted April 23, 2009 Author Share Posted April 23, 2009 Thanks for the advice.....actually, it's my fault, the mail code I sent you was incorrect. My actual code is exactly what you have. I don't know why I copied the other stuff to the end of the php code.....just a mistake. So with my mail.php being perfect...is there any advice as to why I might still be having a problem? After submitting the page it goes to: mail. mail.php/busprofile-2.php?BusID=xxxxx and it sends the email but does not insert the data. Quote Link to comment https://forums.phpfreaks.com/topic/155389-php-email-problem-and-submit-button/#findComment-817905 Share on other sites More sharing options...
mikesta707 Posted April 23, 2009 Share Posted April 23, 2009 maybe your actual mail.php code tries to add to the database, but the code you posted does nothing concerning inserting data into databases... try posting your actual mail.php code so i can look at it Quote Link to comment https://forums.phpfreaks.com/topic/155389-php-email-problem-and-submit-button/#findComment-817915 Share on other sites More sharing options...
DarkSuperHero Posted April 23, 2009 Share Posted April 23, 2009 from the code in the original post it looks like your trying to use php & javascript .....does your code still look like this? <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="fan" id="fan"> <input name="yourfan" type="image" value="Submit" onClick="<?php if(isset($_POST['yourfan'])) { $to = $row_Bus['Email']; $subject = 'You Have A Fan !'; $body = "blah...blah...blah.... "; $headers = "From: admin@mysite.com\r\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1 \n"; $mail_sent = mail( $to, $subject, $body, $headers ); }//nothing echos inside your php....just a note... :-P ?>MM_popupMsg('It\'s official! You are now a fan.')" src="/FANBUT2.png" alt="Become A Fan"/> </label> <input type="hidden" name="MM_insert" value="fan" /> </form> to make it more readable do this... <?php if(isset($_POST['yourfan'])) { $to = $row_Bus['Email']; $subject = 'You Have A Fan !'; $body = "blah...blah...blah.... "; $headers = "From: admin@mysite.com\r\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1 \n"; $mail_sent = mail( $to, $subject, $body, $headers ); }//nothing echos inside your php....just a note... :-P ?> <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="fan" id="fan"> <input name="yourfan" type="image" value="Submit" onClick="MM_popupMsg('It\'s official! You are now a fan.')" src="/FANBUT2.png" alt="Become A Fan"/> </label> <input type="hidden" name="MM_insert" value="fan" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/155389-php-email-problem-and-submit-button/#findComment-817929 Share on other sites More sharing options...
social Posted April 23, 2009 Author Share Posted April 23, 2009 Hi, thanks for your help....I figured it out. I just needed to add the insert code to the mail.php....which i did earlier but I needed to clean up the codes and get rid of a few stuff. Thanks for all your help. Quote Link to comment https://forums.phpfreaks.com/topic/155389-php-email-problem-and-submit-button/#findComment-817936 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.