Fixxer Posted December 18, 2007 Share Posted December 18, 2007 This is not working, how can I send form data using PHP? <?php mail("[email protected]","TMD Music Inquiry",$_POST["name"],"[email protected]"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/82126-solved-sending-form-input-as-e-mail-using-php/ Share on other sites More sharing options...
Fixxer Posted December 18, 2007 Author Share Posted December 18, 2007 Ive found some obvious errors, now I can send the mail, but the $_POST variables are not being sent, they are just blank. <?php $sender = $_POST["email"]; $name = $_POST["name"]; $day = $_POST["dd"]; $month = $_POST["mm"]; $year = $_POST["yy"]; $today = date("l, F j, Y, g:i a") ; $body = "Date: $today \n Name: $name \n Date Of Event: $date / $month / $year"; ?> Sending Request... <?php mail("[email protected]","TMD Music Inquiry",$body,$sender); ?> Quote Link to comment https://forums.phpfreaks.com/topic/82126-solved-sending-form-input-as-e-mail-using-php/#findComment-417344 Share on other sites More sharing options...
~n[EO]n~ Posted December 18, 2007 Share Posted December 18, 2007 Your code should be like this, your current code does not send the post value because it sends the mail when the page loads and your post values are blank <?php // when user presses submit button // name of button is submit here.... if (isset($_POST['submit'])) { $sender = $_POST["email"]; $name = $_POST["name"]; $day = $_POST["dd"]; $month = $_POST["mm"]; $year = $_POST["yy"]; $today = date("l, F j, Y, g:i a") ; $body = "Date: $today \n Name: $name \n Date Of Event: $date / $month / $year"; mail("[email protected]","TMD Music Inquiry",$body,$sender); ?> Quote Link to comment https://forums.phpfreaks.com/topic/82126-solved-sending-form-input-as-e-mail-using-php/#findComment-417363 Share on other sites More sharing options...
Fixxer Posted December 18, 2007 Author Share Posted December 18, 2007 Now nothing sends. I guess for some reason the data isnt being passed from page to page. the forms action is to the page with this script, and the method is post. Here is the updated code. No mail is sent and nothing is written where echo is either. The page loads up fine though. <?php if(isset($_POST['submit'])) { $sender = "TMD-Music.com"; $name = $_POST['name']; $day = $_POST['dd']; $month = $_POST['mm']; $year = $_POST['yy']; $today = date("l, F j, Y, g:i a") ; $body ="This message was auto generated by TMD-Music.com on: $today \n Name: $name \n Date Of Event: $date / $month / $year"; mail("[email protected]","TMD Music Inquiry",$body,$sender); } ?> Your request has been sent. <br /> <br /> <a href="http://www.tmd-music.com"> Click here to return to TMD-Music.com </a> <br /> <br /> ------------------------------------------------------ <php echo $name ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/82126-solved-sending-form-input-as-e-mail-using-php/#findComment-417379 Share on other sites More sharing options...
~n[EO]n~ Posted December 18, 2007 Share Posted December 18, 2007 Can you post your form code.. is the name of the button submit, case sensitive Quote Link to comment https://forums.phpfreaks.com/topic/82126-solved-sending-form-input-as-e-mail-using-php/#findComment-417384 Share on other sites More sharing options...
Fixxer Posted December 18, 2007 Author Share Posted December 18, 2007 contact.php <table bgcolor="white" border="0" align="left" cellpadding="5" width="570"> <tr bgcolor="white"> <td bgcolor="white"> <h3>E-Mail Us</h3> <br /> <br /> <form name="contact" action="mailer.php?" method="post" enctype="text/plain"> Name: <input type="text" name="name" size="25"> <br /> Date Of Event (dd / mm / yy): <input type="text" name="dd" size="2"> <input type="text" name="mm" size="2"> <input type="text" name="yy" size="2"> <br /> Type Of Party: <input type="text" name="type" size="30"> <br /> Phone Number: <input type="text" name="phone" size="12"> <br /> E-Mail Address: <input type="text" name="email" size="25"> <br /> Questions: <textarea name="questions" rows="5" cols="60"></textarea> <br /> <br /> <input type="submit" value="Submit" name="submit"> <input type="reset" value="Reset" name="reset"> </form> </td> </tr> </table> mailer.php <?php $sender = "TMD-Music.com"; $name = $_POST['name']; $date = $_POST['dd']; $month = $_POST['mm']; $year = $_POST['yy']; $type = $_POST['type']; $phone = $_POST['phone']; $email = $_POST['email']; $text = $_POST['text']; $today = date("l, F j, Y, g:i a") ; $body ="This message was auto generated by TMD-Music.com on: $today \n Name: $name \n Date Of Event: $date / $month / $year" \n Type Of Event: $type \n Phone Number: $phone \n E-Mail: $email \n Message: $text "; mail("[email protected]","TMD Music Inquiry",$body,$sender); ?> Your request has been sent. <br /> <br /> <a href="http://www.tmd-music.com"> Click here to return to TMD-Music.com </a> <br /> <br /> ------------------------------------------------------ <php echo $name ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/82126-solved-sending-form-input-as-e-mail-using-php/#findComment-417390 Share on other sites More sharing options...
updwebmaster Posted December 18, 2007 Share Posted December 18, 2007 Ok I have my own code. It's purpose is different, but it has the same general script: $email = $_POST["Email"]; $name = $_POST["Name"] $tags = $_POST["Tags"] $date = $_POST["Date"] $oemail = $_POST["other_emails"] $to = '[email protected],$email'; $subject = 'Application for Joining'; $from = 'From: $email'; $current = date(n/j/y g:i:s e) $text = 'Submission: $current \n Name: $name \n Tags: $tags \n Date: $date \n Email: $email \n Other Emails: $oemail \n'; mail($to,$subject,$text); Quote Link to comment https://forums.phpfreaks.com/topic/82126-solved-sending-form-input-as-e-mail-using-php/#findComment-417398 Share on other sites More sharing options...
~n[EO]n~ Posted December 18, 2007 Share Posted December 18, 2007 Now try this contact.php <table bgcolor="white" border="0" align="left" cellpadding="5" width="570"> <tr bgcolor="white"> <td bgcolor="white"> <h3>E-Mail Us</h3> <br /> <br /> <form name="contact" action="mailer.php" method="post" enctype="multipart/form-data"> Name: <input type="text" name="name" size="25"> <br /> Date Of Event (dd / mm / yy): <input type="text" name="dd" size="2"> <input type="text" name="mm" size="2"> <input type="text" name="yy" size="2"> <br /> Type Of Party: <input type="text" name="type" size="30"> <br /> Phone Number: <input type="text" name="phone" size="12"> <br /> E-Mail Address: <input type="text" name="email" size="25"> <br /> Questions: <textarea name="questions" rows="5" cols="60"></textarea> <br /> <br /> <input name="frm_action1" type="hidden" value="1" /> <input type="submit" value="Submit" name="submit"> <input type="reset" value="Reset" name="reset"> </form> </td> </tr> </table> mailer.php <?php if(isset($_POST['frm_action1']) && $_POST['frm_action1']==1) { $sender = "TMD-Music.com"; $name = $_POST['name']; $date = $_POST['dd']; $month = $_POST['mm']; $year = $_POST['yy']; $type = $_POST['type']; $phone = $_POST['phone']; $email = $_POST['email']; $text = $_POST['text']; $today = date("l, F j, Y, g:i a") ; $body ='This message was auto generated by TMD-Music.com on: {$today}' . "\r\n" . 'Name: {$name}' . "\r\n" . 'Date Of Event: {$date} / {$month} / {$year}"' . "\r\n" . 'Type Of Event: {$type}' . "\r\n" . 'Phone Number: {$phone}' . "\r\n" . 'E-Mail: {$email}' . "\r\n" . 'Message: {$text}'; mail("[email protected]","TMD Music Inquiry",$body,$sender); } else { echo "Errors Occured...."; } ?> Your request has been sent. <br /> <br /> <a href="http://www.tmd-music.com"> Click here to return to TMD-Music.com </a> <br /> <br /> ------------------------------------------------------ <?php echo $name ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/82126-solved-sending-form-input-as-e-mail-using-php/#findComment-417400 Share on other sites More sharing options...
Fixxer Posted December 18, 2007 Author Share Posted December 18, 2007 it says errors occured when i fill out the form and click submit. Quote Link to comment https://forums.phpfreaks.com/topic/82126-solved-sending-form-input-as-e-mail-using-php/#findComment-417406 Share on other sites More sharing options...
~n[EO]n~ Posted December 18, 2007 Share Posted December 18, 2007 Did you paste contact.php too I had added this <input name="frm_action1" type="hidden" value="1" /> Quote Link to comment https://forums.phpfreaks.com/topic/82126-solved-sending-form-input-as-e-mail-using-php/#findComment-417408 Share on other sites More sharing options...
Fixxer Posted December 18, 2007 Author Share Posted December 18, 2007 yes i did. Quote Link to comment https://forums.phpfreaks.com/topic/82126-solved-sending-form-input-as-e-mail-using-php/#findComment-417410 Share on other sites More sharing options...
~n[EO]n~ Posted December 18, 2007 Share Posted December 18, 2007 Please check it again, there must be some mistake when you pasted.... Your same code is working here Quote Link to comment https://forums.phpfreaks.com/topic/82126-solved-sending-form-input-as-e-mail-using-php/#findComment-417413 Share on other sites More sharing options...
Fixxer Posted December 18, 2007 Author Share Posted December 18, 2007 Yes, It is correctly pasted I re copied and pasted both files. And I got the one you sent, and this is what the e-mail contained. TMD-Music.com This message was auto generated by TMD-Music.com on: {$today} Name: {$name} Date Of Event: {$date} / {$month} / {$year}" Type Of Event: {$type} Phone Number: {$phone} E-Mail: {$email} Message: {$text} Quote Link to comment https://forums.phpfreaks.com/topic/82126-solved-sending-form-input-as-e-mail-using-php/#findComment-417414 Share on other sites More sharing options...
updwebmaster Posted December 18, 2007 Share Posted December 18, 2007 Just wondering if one of you could look at my script I posted earlier the script that I'm using. The form page is here: UPD Application for Battle Quote Link to comment https://forums.phpfreaks.com/topic/82126-solved-sending-form-input-as-e-mail-using-php/#findComment-417416 Share on other sites More sharing options...
~n[EO]n~ Posted December 18, 2007 Share Posted December 18, 2007 Oops.. sorry i didn't notice that now replace this, hope this works, i will be checking too... <?php if(isset($_POST['frm_action1']) && $_POST['frm_action1']==1) { $sender = "TMD-Music.com"; $name = $_POST['name']; $date = $_POST['dd']; $month = $_POST['mm']; $year = $_POST['yy']; $type = $_POST['type']; $phone = $_POST['phone']; $email = $_POST['email']; $text = $_POST['text']; $today = date("l, F j, Y, g:i a") ; $body ='This message was auto generated by TMD-Music.com on: {$today}' . "\r\n" . 'Name: "'.$name.'"' . "\r\n" . 'Date Of Event: "'.$date.'" / "'.$month.'"/ "'.$year.'""' . "\r\n" . 'Type Of Event: "'.$type.'"' . "\r\n" . 'Phone Number: "'.$phone.'"' . "\r\n" . 'E-Mail: "'.$email.'"' . "\r\n" . 'Message: "'.$text.'"'; mail("[email protected]","TMD Music Inquiry",$body,$sender); } else { echo "Errors Occured...."; } ?> Your request has been sent. <br /> <br /> <a href="http://www.tmd-music.com"> Click here to return to TMD-Music.com </a> <br /> <br /> ------------------------------------------------------ <?php echo $name ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/82126-solved-sending-form-input-as-e-mail-using-php/#findComment-417419 Share on other sites More sharing options...
Fixxer Posted December 18, 2007 Author Share Posted December 18, 2007 Okay, that is sending now, but the date is mssed up. Also I know that the variable names for message were not matching up earlier, but I have changed that. Here is what is mailed. ---------------------------------------------------- TMD-Music.com This message was auto generated by TMD-Music.com on: {$today} Name: "Joe" Date Of Event: "12" / "18"/ "07"" Type Of Event: "Fun" Phone Number: "555-5555" E-Mail: "[email protected]" Message: "" Quote Link to comment https://forums.phpfreaks.com/topic/82126-solved-sending-form-input-as-e-mail-using-php/#findComment-417422 Share on other sites More sharing options...
~n[EO]n~ Posted December 18, 2007 Share Posted December 18, 2007 You can fix that, can't you and your form is also not validated. Blank submission also goes.... Quote Link to comment https://forums.phpfreaks.com/topic/82126-solved-sending-form-input-as-e-mail-using-php/#findComment-417425 Share on other sites More sharing options...
Fixxer Posted December 18, 2007 Author Share Posted December 18, 2007 Okay this works now. Thanks!!! <?php if(isset($_POST['frm_action1']) && $_POST['frm_action1']==1) { $sender = "TMD-Music.com"; $name = $_POST['name']; $date = $_POST['dd']; $month = $_POST['mm']; $year = $_POST['yy']; $type = $_POST['type']; $phone = $_POST['phone']; $email = $_POST['email']; $text = $_POST['questions']; $today = date("l, F j, Y, g:i a") ; $body ="This message was auto generated by TMD-Music.com on: $today Name: $name Date Of Event: $date / $month / $year Type Of Event: $type Phone Number: $phone \n E-Mail: $email \n Message: $text"; mail("[email protected]","TMD Music Inquiry",$body,$sender); } else { echo "Error." ; } ?> Your request has been sent. <br /> <br /> <a href="http://www.tmd-music.com"> Click here to return to TMD-Music.com </a> <br /> <br /> ------------------------------------------------------ <br /> <br /> <?php echo $name ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/82126-solved-sending-form-input-as-e-mail-using-php/#findComment-417427 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.