Jump to content

Multipage PHP form with email


CyberWrek

Recommended Posts

Hi there,

 

I apologize ahead of time for what is going to seem absolutely noob-ish. I'm having some trouble with my multipage PHP scripts and need some assistance. If you are responding to this, please bear in mind that, up until Feb 20th, I had never knowingly used PHP before, only HMTL.

 

I copied some pre-fab PHP scripts for a multipage PHP form a few days ago and wanted to have the form not only bring up a confirmation page (for my clients to see what they entered), but also a thank you page that would open after the SUBMIT button was pressed on the confirmation page.

 

So far, I've kept the data flowing through the forms, right up until the client presses the SUBMIT button. No data gets sent in the email. I've spent the past three days messing with the script on my Final.php and Thanks.php pages that I fear I've messed it up beyond salvaging. :'(

 

Can anyone have a look at these pages and let me know what I should be doing differently? The main part of my site isn't up yet, so this link will take you to the first page of the test form I'm working with.

 

www.directbc.ca/form1.php

 

Any help would be phenomenal.

 

Cheers

Link to comment
https://forums.phpfreaks.com/topic/39851-multipage-php-form-with-email/
Share on other sites

<?php

include ('fieldforwarder.php');

    $cust_name = htmlentities($_POST['cust_name']);

    $cust_email = htmlentities($_POST['cust_email']);

    $cust_address = htmlentities($_POST['cust_address']);

    $cust_phone = htmlentities($_POST['cust_phone']);

?>

<HTML>

<HEAD>

<TITLE>Multi-page Form - Final</TITLE>

</HEAD>

<BODY>

<form action="thanks.php" method="post">

<p>You filled in:</p>

Name: <?php echo $cust_name; ?><BR>

Email: <?php echo $cust_email; ?>"<BR>

Address: <?php echo $cust_address; ?><BR>

Phone: <?php echo $cust_phone; ?><BR>

<input type="submit" value="Submit">

</form>

 

</BODY>

</HTML>

<?php

include ('fieldforwarder.php');

$cust_name = htmlentities($_POST['cust_name']);

    $cust_email = htmlentities($_POST['cust_email']);

    $cust_address = htmlentities($_POST['cust_address']);

    $cust_phone = htmlentities($_POST['cust_phone']);

?>

<html>

 

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<title>New Page 1</title>

</head>

 

<body>

<p> Thank you for your submission </p>

<script language="php">

$email = $HTTP_POST_VARS;

$mailto = "[email protected]";

$mailsubj = "Application for Basic Listing";

$mailhead = "From: $cust_email\n";

reset ($HTTP_POST_VARS);

$mailbody = "Name: <?php echo $cust_name; ?><BR>

Email: <?php echo $cust_email; ?><BR>

Address: <?php echo $cust_address; ?><BR>

Phone: <?php echo $cust_phone; ?>\n";

while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }

if (!eregi("\n",$HTTP_POST_VARS)) { mail($mailto, $mailsubj, $mailbody, $mailhead); }

</script>

</body>

 

</html>

 

If someone can help with this, I'd be most appreciative. It's the only thing standing in the way of getting my site up and running for business. If someone can solve the problem to get me going, I'll be sure to make a regular contribution to the phpfreaks.com cause once I get some revenue going. ;)

 

Also, if you need my Form1.php and Form2.php scripts posted, I can do that, I just didn't want to post it unnecessarily.

 

Cheers.

try this:

 



<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<?php

echo "Thank you for your submission";

include ('fieldforwarder.php');
$cust_name = htmlentities($_POST['cust_name']); 
$cust_email = htmlentities($_POST['cust_email']); 
$cust_address = htmlentities($_POST['cust_address']); 
$cust_phone = htmlentities($_POST['cust_phone']); 

$email = $HTTP_POST_VARS;
$mailto = "[email protected]";
$mailsubj = "Application for Basic Listing";
$mailhead = "From: " . $cust_email . "\n";
reset ($HTTP_POST_VARS);
$mailbody = "Name: " . $cust_name . "<BR>";
echo "Email: " . $cust_email . "<BR>";
echo "Address: " . $cust_address . "<BR>";
echo "Phone: " . $cust_phone . "\n";
while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }
if (!eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto, $mailsubj, $mailbody, $mailhead); }

?>

</html>

 

Hi Archadian,

 

I appreciate the code. I replaced my old Thanks.php script with it and tried it, but it produced this on the actual page:

 

 

Thank you for your submission Email:

Address:

Phone:

 

 

The email was received, so at least I know that portion is still working and this time, rather than getting nothing at all, the name: <BR>  (from line 23) showed up in the message. lol. I think this is a step closer than what I had before. I tried tinkering with the code to see if I could manipulate it, but just kept coming up with error messages. I left your code in place for now.

 

Any other ideas?

I also forgot to mention that neither my script nor the new one produced a "FROM" email address. I've had other scripts that look similar work just fine over the past day or so. This baffles me. Ah, but most things will when you're running on fumes. Need sleep. zzzzzzzzzz

echo "Address: " . $cust_address . "<BR>";

echo "Phone: " . $cust_phone . "\n";

 

maybe your variables here aren't being set somehow

 

also maybe ur putting $mailhead in the wrong part of the mail() function?

 

Unless ur trying to put it INSIDE the email with $mailbody then take out the , after $mailbody

Hi again,

 

I looked at the script and changed a couple of things around. In the mail() function, I switched the $mailhead and $mailbody around. Now I receive a FROM email address where it's supposed to be, but the address is that of my server, not the person sending the email. On top of that, now the "From" appears in the body of the email. Weird.

 

I'm not sure what you meant by removing the , from $mailbody. I assume you meant in the mail() function. Now that I switched the $mailhead and $mailbody around, there is no comma after $mailbody, so that kind of solves that issue. But I actual need all of the data that a user enters when using my form pages. So, when I receive the email, I need the name, address, phone number, etc, in the body of the email.

 

I'll keep staring at the code. Maybe something will jump out at me. Maybe not. If you can help any further, great. If not, no worries. Thanks for the effort you put into this. It is much appreciated.

still post the code from the form you are using but i just saw something.

 

try this on this part of the code:

 


$mailbody = "From: " . $cust_email . "<br>Name: " . $cust_name . "<br>Email: " . $cust_email . "<br>Address: " . $cust_address . "<br>Phone: " . $cust_phone . "\n";


 

and just delete the $mailhead altogether, that and the info its set to.

<HTML>

<HEAD>

<TITLE>Multi-page Form - Page One</TITLE>

</HEAD>

<BODY>

<p>Please fill in the following information</p>

<FORM METHOD="POST" ACTION="form2.php">

Name: <INPUT TYPE="text" SIZE="40" name="cust_name"><BR>

Email: <INPUT TYPE="text" SIZE="40" name="cust_email"><BR>

<INPUT TYPE="submit" name="submit1" value="Proceed">

</FORM>

</BODY>

</HTML>

<?php 

    include ('fieldforwarder.php');

?>

<HTML>

<HEAD>

<TITLE>Multi-page Form - Page Two</TITLE>

</HEAD>

<BODY>

<p>Please fill in the following information</p>

<FORM METHOD="POST" ACTION="final.php">

Address: <INPUT TYPE="text" SIZE="50" name="cust_address"><BR>

Phone: <INPUT TYPE="text" SIZE="20" name="cust_phone"><BR>

<?php echo field_forwarder(); ?>

<INPUT TYPE="submit" name="submit2" value="Proceed">

</FORM>

</BODY>

</HTML>

<?php

function field_forwarder() {

    global $_POST, $rEM979, $FFoutputType;

    $fieldForwarder = '';

    /* get the arguments passed */

    $argList = func_get_args ();

 

    /* globalize any other set of instructions */

    if (count ($argList)) {

        eval ('global $' . $argList[count($argList)-1] . ';');

    }

   

    /* set the default set of values to convert */

    if(count($argList)==0) {

        /* if the function is initially passed without

          parameter we're looking in $_POST */

        $argList[0] = '_POST';

        $startValue = $_POST; 

        if (sizeof ($startValue) == 0) {

            return false;

        }

    } elseif (count ($argList) == 1) {

        eval ('$rEM979["' . $argList[0] . '"] = $' 

              . $argList[0] . ';');

        $argList[0] = 'rEM979';

        $startValue = $rEM979;

    } elseif (count ($argList) == 2) {

        eval ('$startValue = $' . $argList[1] . '["' 

              . $argList[0] . '"];');

    } else {

        for($e = count($argList) - 2; $e >= 0; $e--) {

            $intersperse .= '["' . $argList[$e] . '"]';

        }

        eval ('$startValue = $' . $argList[count($argList)-1] 

              . $intersperse . ';');

    }

 

    foreach($startValue as $n => $v) {

        if (is_array ($v)) {

            /* call the function again */

            $shiftArguments = '';

            for($w = 0; $w <= count ($argList) - 1; $w++) {

                $shiftArguments .= '"' . $argList[$w] . '", ';

            }

            $shiftArguments = substr ($shiftArguments, 0, 

                                    strlen ($shiftArguments) - 2);

           

            eval ('$fieldForwarder .= field_forwarder("' . $n . '"' 

                  . substr(',',0,strlen($shiftArguments)) . ' ' 

                  . $shiftArguments . ');');

                       

        } else {

            /* we have an root value finally */

            if (count ($argList) == 1) {

                /* actual output */

                flush();

                if ($FFoutputType == 'print') {

                    $fieldForwarder .= "\$$n = '$v';\n";

                } else {

                    $fieldForwarder .= "<input type=\"hidden\" "

                                    . "name=\"$n\" value=\"" 

                                    . htmlentities(stripslashes($v)) 

                                    . "\">\n";

                }

            } elseif (count ($argList) >1 ) {

                $indexString = '';

                for($g = count ($argList) - 3; $g >= 0; $g--) {

                    $indexString .= '[' 

                                . ((!is_numeric ($argList[$g])

                                and $FFoutputType == 'print')

                                ? "'" : '')

                                . $argList[$g]

                                . ((!is_numeric ($argList[$g])

                                and $FFoutputType == 'print')

                                ? "'" : '')

                                . ']';

                }

                $indexString .= '[' 

                            . ((!is_numeric ($n) 

                            and $FFoutputType == 'print') 

                            ? "'" : '') . $n 

                            . ((!is_numeric ($n) 

                            and $FFoutputType == 'print') 

                            ? "'" : '') . ']';

                /* actual output */

                flush();

                if ($FFoutputType == 'print') {

                    $fieldForwarder .= "\${$argList[count($argList)-2]}"

                                    . "$indexString = '$v';\n";

                } else {

                    $fieldForwarder .= "<input type=\"hidden\" name=\""

                                    . "{$argList[count($argList)-2]}"

                                    . "$indexString\" value=\"" 

                                    . htmlentities(stripslashes($v)) 

                                    . "\">\n";

                }

            }

        }       

    }

    return $fieldForwarder;

}

?>

I did what you suggested and now all I get in the From part of the email is  br

 

Nothing else comes up in the body of the email. I'm almost thinking I botched the code up so badly that I need to start from scratch. If you can suggest otherwise, I'm all ears. :-\

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.