allotrope Posted November 26, 2007 Share Posted November 26, 2007 Hello there, I'm new to PHP from this morning & it's all very exciting! I was wondering if someone might be able to help me: I have created a form & want to send the results via php to my email address. I've used the mail function & I think I have to define the $message as equal to the all the fields of my form (i.e. name, otherformtextinfield etc.. except email). Can anyone give me advice on how to do this? I had hope that when i had ...... , $message, ......) i could add my form fields to that i.e. ........, $message $name $otherformtextinfield, ...... but that didn't work! Probably Thanks Allotrope. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 26, 2007 Share Posted November 26, 2007 There are many ways of doing this. Perhaps the easiest is to use the print_r() to dump the values of the $_POST array into your message. It's not really formatted nicely, but it is quick: <?php $message = 'The following information was entered:' . "\n"; $message .= print_r($_POST,true); mail($to,$subject,$message); ?> Ken Quote Link to comment Share on other sites More sharing options...
allotrope Posted November 26, 2007 Author Share Posted November 26, 2007 Thanks Ken I appreciate your response. I tried what you said... <?php $message = 'The following information was entered:' . "\n"; $message .= print_r($_POST,true); mail( "myemail@something.com", "Newsletter Request", $message, "From: $Email" ); header( "Location: http://www.website.co.uk" ); ?> However I'm not sure then how to create an array? I had tried this <?php $message = $_REQUEST['Name'], $_REQUEST['Salon'] ; mail( "myemail@something.com", "Newsletter Request", $message, "From: $Email" ); header( "Location: http://www.website.co.uk" ); ?> Which I know is wrong! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 26, 2007 Share Posted November 26, 2007 My solution gives you what you're looking for. Why do you want to create an array? Also, while you're testing, don't use the header() function which will redirect your script to a different site. Why are you doing that? Ken Quote Link to comment Share on other sites More sharing options...
allotrope Posted November 26, 2007 Author Share Posted November 26, 2007 I started learning PHP this morning to add a join newsletter form to a website this morning. So I learn't how to do it in part from here .. h**p://www.thesitewizard.com/archive/feedbackphp.shtml (to explain why I put the website header). I don't know how to use the $_POST function so I can't quite piece it all together. I will post my form if you have the time to look at it.. <div id="form"> <script language="JavaScript" src="form.js" type="text/javascript"></script> <form id="Newsletter" name="form1" method="post" action="sendflsmailb.php"> <input type="text" id="inputname" value="Name" name="Name" onfocus="inputName(); style.color='#000'; style.borderColor='#000';" onblur="inputNameOff(); style.borderColor='';" /><br /> <input type="text" id="inputemail" value="Email" name="Email" onfocus="inputEmail(); style.color='#000'; style.borderColor='#000';" onblur="inputEmailOff(); style.borderColor='';" /><br /> <input type="text" id="inputsalon" value="Salon" name="Salon" onfocus="inputSalon(); style.color='#000'; style.borderColor='#000';" onblur="inputSalonOff(); style.borderColor='';" /><br /> <input name="Send" type="submit" value="Join Our Newsletter" /> </form> </div> Could you recommend anywhere to learn PHP online? Thank you! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 26, 2007 Share Posted November 26, 2007 The $_POST superglobal array will contain all the values passed to your script from the form. A good place to learn PHP is W3 Schools. You can also download Apache/PHP/MySQL to your PC and run a local webserver, so you can test things without uploading to a host. I use xampp Ken Quote Link to comment Share on other sites More sharing options...
allotrope Posted November 26, 2007 Author Share Posted November 26, 2007 Thank you! I am familiar with W3 & I will download the PHP to test it locally. I have tried the script you suggested but I only get '1' returned in the message body. Thanks for your time. A Quote Link to comment Share on other sites More sharing options...
allotrope Posted November 26, 2007 Author Share Posted November 26, 2007 Hi Ken, Just to let you know, I tried the script again just now & it worked, I must have missed smomething! Thank you so much, I'm sure I will want to do other stuff with it soon but I'm really grateful for your help. A Quote Link to comment 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.