Brian Walton Posted October 28, 2009 Share Posted October 28, 2009 I'm new to PHP so please be gentle. I have a little php script below that works well. The "$msgVar" goes into the body message of the email. How can I effect additional fields that can be filled with information that also go into the body of the email in such a way that they have there own seperate fields of answers with atleast a double space between each field that is answered. For example: With thanks. Brian Answer One: Answer Two: Answer Three: <? if ($send=="yes") { $to = "my@address"; $subject = "$subjectVar"; $body .= "$msgVar"; $from = "$nameVar"; $tfrom = "From: <$emailVar>"; mail($to,$subjectVar,$msgVar,$tfrom); } echo "&errormessage=Email has been sent&"; ?> Link to comment https://forums.phpfreaks.com/topic/179335-extra-fields-in-main-body-and-php-required/ Share on other sites More sharing options...
Bricktop Posted October 28, 2009 Share Posted October 28, 2009 Hi Brian Walton, Post your full code to enable us to give a more definitive answer. Link to comment https://forums.phpfreaks.com/topic/179335-extra-fields-in-main-body-and-php-required/#findComment-946197 Share on other sites More sharing options...
Brian Walton Posted October 28, 2009 Author Share Posted October 28, 2009 Sorry that's all the code I have for the php file I have. Brian Link to comment https://forums.phpfreaks.com/topic/179335-extra-fields-in-main-body-and-php-required/#findComment-946199 Share on other sites More sharing options...
Bricktop Posted October 28, 2009 Share Posted October 28, 2009 Hi Brian Walton, $msgVar, $subjectVar and $nameVar must be being defined somewhere and it's not in the code you posted. Generally speaking, you will find something like this somewhere in your file: $msgVar = $_POST['message']; $subjectVar = $_POST['subject']; $nameVar = $_POST['name']; Do you have some HTML code you're using along with this PHP code? If so, post that code too. Link to comment https://forums.phpfreaks.com/topic/179335-extra-fields-in-main-body-and-php-required/#findComment-946202 Share on other sites More sharing options...
Brian Walton Posted October 28, 2009 Author Share Posted October 28, 2009 This is effected within a flash macromedia movie. I have found the following that relates to the fields for the moment: Hope this helps. Brian on (release) { if((nameVar=="")||(emailVar=="")||(subjectVar=="")||(msgVar=="")) { errormessage="Please fill all the fields"; } else { errormessage="Sending...."; send="yes"; this.loadVariables("contact.php",'POST'); send="no"; nameVar=""; emailVar=""; subjectVar=""; msgVar=""; } } Link to comment https://forums.phpfreaks.com/topic/179335-extra-fields-in-main-body-and-php-required/#findComment-946210 Share on other sites More sharing options...
Bricktop Posted October 28, 2009 Share Posted October 28, 2009 OK, it's becoming clearer now - so it's a Flash/PHP script. Without seeing the full code this is going to be difficult but somewhere in the code is going to be the actual "form" elements, by that I mean the input boxes where a user types their name, email address, subject and message. Each one of these elements will be named as nameVar, emailVar, subjectVar, and msgVar. In theory, to add extra fields, add them to the form and give them unique names, e.g. answer1Var, answer2Var and answer3Var. Then, in the code above do something like: on (release) { if((nameVar=="")||(emailVar=="")||(subjectVar=="")||(msgVar=="")||(answer1Var=="")||(answer2Var=="")||(answer3Var=="")) { errormessage="Please fill all the fields"; } else { errormessage="Sending...."; send="yes"; this.loadVariables("contact.php",'POST'); send="no"; nameVar=""; emailVar=""; subjectVar=""; msgVar=""; answer1Var=""; answer2Var=""; answer3Var=""; } } Then, in the PHP do something like: <? if ($send=="yes") { $to = "my@address"; $subject = "$subjectVar"; $body .= "$msgVar\n\n$answer1Var\n\n$answer2Var\n\n$answer3Var"; $from = "$nameVar"; $tfrom = "From: <$emailVar>"; mail($to,$subjectVar,$body,$tfrom); } echo "&errormessage=Email has been sent&"; ?> Again, without seeing your full code it's very hard to say whether the above is correct but hopefully this should give you some indication of the steps you're going to have to perform to achieve your desired result. Hope this helps. Link to comment https://forums.phpfreaks.com/topic/179335-extra-fields-in-main-body-and-php-required/#findComment-946222 Share on other sites More sharing options...
Brian Walton Posted October 28, 2009 Author Share Posted October 28, 2009 I thank you so much for your time on the matter. I will give it a try. Brian Link to comment https://forums.phpfreaks.com/topic/179335-extra-fields-in-main-body-and-php-required/#findComment-946224 Share on other sites More sharing options...
Brian Walton Posted October 28, 2009 Author Share Posted October 28, 2009 It works well. Many thanks The answer to 1,2 and 3 all arrive in the message area. And they have a double space gap between them! Well done. Last thing. Is there anyway of getting the name of the field in the email reply. For example: Answer 1: And this is the answer that has been given Answer 2: And this is the answer that has been given Without the name be given it will be rather confusing to establish what reply goes to what answer. And truely as a last request, is it possible to effect a tick or cross as a reply in php. Some of my questions could be shortand by the use of a tick and cross...just wondering. with thanks Brian Link to comment https://forums.phpfreaks.com/topic/179335-extra-fields-in-main-body-and-php-required/#findComment-946237 Share on other sites More sharing options...
Bricktop Posted October 28, 2009 Share Posted October 28, 2009 Hi Brian, No problem at all. In answer to your first question, yes that's possible, just change your PHP code to read: <? if ($send=="yes") { $to = "my@address"; $subject = "$subjectVar"; $body .= "$msgVar\n\nAnswer 1: $answer1Var\n\nAnswer 2: $answer2Var\n\nAnswer 3: $answer3Var"; $from = "$nameVar"; $tfrom = "From: <$emailVar>"; mail($to,$subjectVar,$body,$tfrom); } echo "&errormessage=Email has been sent&"; ?> In answer to your second question, yes that's also possible. Tickboxes send an "on" or "off" response, but these responses aren't very "user friendly". To get around this you could do something along the lines of: if($tickboxVar=="on") { $tickboxVar="Yes"; } else { $tickboxVar="No"; } Hope this helps. Link to comment https://forums.phpfreaks.com/topic/179335-extra-fields-in-main-body-and-php-required/#findComment-946242 Share on other sites More sharing options...
Brian Walton Posted October 28, 2009 Author Share Posted October 28, 2009 Give yourself a t pat on the back. Many thanks for your help. Off to bed now at the bottom of the world. Brian Link to comment https://forums.phpfreaks.com/topic/179335-extra-fields-in-main-body-and-php-required/#findComment-946246 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.