mulderthe23rd Posted May 11, 2010 Share Posted May 11, 2010 I'll be honest: I'm a senior in an ITP program and I don't know much about PHP. (Hell, the shop instructor knows less than I do!) But I decided to try it on a website I need to make. And since I'm posting here, I think you can guess how well it went. I can get the email to send, but it doesn't take information - specifically, from a drop-down menu. So, let's see if we can go over the code and find out the right's and wrongs. Please? (And yes, it is a Harry Potter website. It had to be themed. ) HTML Form: <form method="post" action="../askmarauders.php"> Your Name: <input type="text" name="yourname"></textarea> <br /> Email: <input name="email" type="text" /> <br /> For: <select name="for"> <option value="Remus">Remus Lupin</option> <option value="Peter">Peter Pettigrew</option> <option value="Sirius">Sirius Black</option> <option value="James">James Potter</option> <option value="Severus">Severus Snape</option> <option value="Lily">Lily Evans</option> <option value="Group">A group (speficy in message)</option> <option value="Anyone">Anyone can answer</option> <option value="all">My question is for everyone!</option> </select> <br /> Message: <br /> <textarea name="txt" rows="15" cols="40"> </textarea> <br /> <input type="submit" name="submit" value="Submit"/> </form> PHP Code: <?php $to = "[email protected]"; $email = $_REQUEST['email']; $subject = "Ask the Marauders"; $for = $_REQUEST['for'] $txt = $_REQUEST['txt']; $headers = "From: $email" . "For: $for" . "\r\n" . "Location: thankyou.htm"; mail($to,$subject,$txt,$headers); ?> Quote clearly, I'm a PHP loser n00b very bad beginner. Can anyone help me figure this out? Quote Link to comment https://forums.phpfreaks.com/topic/201323-html-form-to-mail-function/ Share on other sites More sharing options...
Pikachu2000 Posted May 11, 2010 Share Posted May 11, 2010 You have the value of the $_REQUEST['for'] select box variable going into the email headers. Should it not be in the body of the email instead? It seems you also are confusing email headers with the PHP header() function. What exactly is the result you are trying to get, from start to finish? Quote Link to comment https://forums.phpfreaks.com/topic/201323-html-form-to-mail-function/#findComment-1056220 Share on other sites More sharing options...
greatstar00 Posted May 11, 2010 Share Posted May 11, 2010 mail header, or http header, or ftp header, is those thing the server sending to each other, telling each other, what kind of information they both receiving like, who it is from, what type of text encoding, how the connection be handled after everything are done etc these header wont be seen in header, and human eyes just the server will see it, and process it by the meaning of the sender like http header http 1.1 200 OK content-type: text/html connection: close the above 3 lines are the most common type of header when u use browser (100% of browser will send this out) do u see these 3 lines? NO so, the header in mail is same, it wont be seen by human eye, except the following From: (maybe more) according to this link, the For header isnt used like the way u do http://www.avolio.com/columns/E-mailheaders.html Quote Link to comment https://forums.phpfreaks.com/topic/201323-html-form-to-mail-function/#findComment-1056227 Share on other sites More sharing options...
sharp.mac Posted May 11, 2010 Share Posted May 11, 2010 the below should process your form, just edit your askmarauders.php to accommodate the following code <?php // recipient $to = '[email protected]' ; // subject $subject = 'Some Subject'; // variables $name = $_POST['yourname']; $email = $_POST['email']; $for = $_POST['for']; $txt = $_POST['txt']; // message $message = " <b>Name: </b>$name \n\n <b>Email: </b>$email \n\n <b>For: </b>$for \n\n <b>Txt: </b>$txt \n\n "; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= "To: YourName <[email protected]>" . "\r\n"; $headers .= "From: $name <$email>" . "\r\n"; // Mail it mail($to, $subject, $message, $headers); ?> Quote Link to comment https://forums.phpfreaks.com/topic/201323-html-form-to-mail-function/#findComment-1056355 Share on other sites More sharing options...
mulderthe23rd Posted May 11, 2010 Author Share Posted May 11, 2010 the below should process your form, just edit your askmarauders.php to accommodate the following code <?php // recipient $to = '[email protected]' ; // subject $subject = 'Some Subject'; // variables $name = $_POST['yourname']; $email = $_POST['email']; $for = $_POST['for']; $txt = $_POST['txt']; // message $message = " <b>Name: </b>$name \n\n <b>Email: </b>$email \n\n <b>For: </b>$for \n\n <b>Txt: </b>$txt \n\n "; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= "To: YourName <[email protected]>" . "\r\n"; $headers .= "From: $name <$email>" . "\r\n"; // Mail it mail($to, $subject, $message, $headers); ?> This is easy enough to follow. But for some reason, it won't take anything from txt. All of the other information works - but the email I receive has nothing in it aside from the name, the email, etc. No actual "message" appears. Oh, and thanks to everyone else who replied A great help. Quote Link to comment https://forums.phpfreaks.com/topic/201323-html-form-to-mail-function/#findComment-1056840 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.