Jump to content

Extra fields in main body and php required.


Brian Walton

Recommended Posts

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&";

?>

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.

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="";

    }

}

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.

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.