Page 1 of 3

PHP mailform

Posted: Wed Jan 22, 2003 8:21 am
by Bjarnat
I have no knowledge of PHP and I wanted to use the php mail form(please see entire code below). Could anybody explain the following to me please:

These two files, do I have to build them or are they being created by the php code? Should these be placed in the same root directory (folder) as for instance the checkout.htm ?

$header = "header.html";
$footer = "footer.html";


Return page, is the page which I want to display after the check out is copleted. Can I use in the code something like this "index.htm target=main"?

$returnpage = "/";

This one I know :lol:

$youremail = "spam@nopdesign.com";

What is this file and where it should be located?

$csvfilename = "orders.csv";

also what's this quote?

$csvquote = "\"\"";

and mode?

$mode = "BOTH";


Thanks for your help and patience!

PHP MAILFORM
--------------------

<?
//=====================================================================||
// NOP Design JavaScript Shopping Cart ||
// PHP SCRIPT Checkout Module ||
// ||
// For more information on SmartSystems, or how NOPDesign can help you ||
// Please visit us on the WWW at http://www.nopdesign.com ||
// ||
// Javascript portions of this shopping cart software are available as ||
// freeware from NOP Design. You must keep this comment unchanged in ||
// your code. For more information contact FreeCart@NopDesign.com. ||
// ||
// JavaScript Shop Module, V.4.3.1 ||
//=====================================================================||
// ||
// Function: Writes available form elements from the NOP ||
// Free Cart (http://www.nopdesign.com/freecart) ||
// and other form elements to an email file, and ||
// send user confirmation ||
// ||
//=====================================================================||


//######################################################################
// #
// User defined variables: #
// $header - string value containing the complete #
// path of the HTML page header #
// $footer - string value containing the complete #
// path of the HTML page footer #
// $youremail - string value containing the email address to #
// send catalog orders in EMAIL or BOTH modes #
// $returnpage - URL to send user when checkout is complete #
// $csvfilename - string value containing the complete #
// path of the user database. #
// $csvquote - string value containing what to use for quotes #
// in the csv file (typically "" or \") #
// $mode - string value containing 'EMAIL', 'FILE' or #
// 'BOTH' to determine if the script should send #
// an email to you with the new order, write the #
// order to a CSV file, or do both. #
//######################################################################
$header = "header.html";
$footer = "footer.html";
$returnpage = "/";
$youremail = "rbsorb@lycos.com";
$csvfilename = "orders.csv";
$csvquote = "\"\"";
$mode = "BOTH";


//##############################################################
//#FUNCTION: doFormError #
//#RETURNS: #
//#PARAMETERS: A error message string. #
//#PURPOSE: Generates an HTML page indicating a form #
//# submission error occurred. #
//##############################################################
function doFormError($errString) {

include($header);

echo "<FONT SIZE=+2>The form you submitted was not complete.<BR><BR></FONT>";
echo "$errString<BR><BR>\n";
echo "<INPUT TYPE=BUTTON ONCLICK='history.back()' VALUE=' Return to the checkout page '><HR>";

include($footer);

exit;
}

//##############################################################
//#FUNCTION: doError #
//#RETURNS: #
//#PARAMETERS: A error message string. #
//#PURPOSE: Generates an HTML page indicating an error #
//# occurred. #
//##############################################################
function doError($errString) {

include($header);

echo "$errString<BR><BR>\n";

include($footer);

exit;
}



//##############################################################
//##############################################################
//### MAIN ###
//##############################################################
//##############################################################

if (($b_first == "") || ($b_last == "") || ($b_addr == "") || ($b_city == "") || ($b_state == "") || ($b_zip == "") || ($b_phone == "") || ($b_email == "")) {
doFormError("I'm sorry, but it appears that you forgot to fill in a required field. Please go <A HREF='Javascript:history.go(-1);'>back</A> and correct the error.");
exit;
}

//# checks for valid email address
if( !(ereg("^(.+)@(.+)\\.(.+)$",$b_email)) ) {
doFormError("You submitted an invalid email address. Please go <A HREF='Javascript:history.go(-1);'>back</A> and correct the error.");
exit;
}

$today = date ("l, F jS Y");
$strMessageBody = "";
$strMessageBody .= "A new order has been received. A summary of this order appears below.\n";
$strMessageBody .= "\n";
$strMessageBody .= "Order Date: $today \n";
$strMessageBody .= " \n";
$strMessageBody .= "Bill To: \n";
$strMessageBody .= "-------- \n";
$strMessageBody .= " $b_first $b_last \n";
$strMessageBody .= " $b_addr \n";
$strMessageBody .= " $b_addr2 \n";
$strMessageBody .= " $b_city, $b_state $b_zip \n";
$strMessageBody .= " $b_phone \n";
$strMessageBody .= " $b_fax \n";
$strMessageBody .= " $b_email \n";
$strMessageBody .= " \n";
$strMessageBody .= " \n";
$strMessageBody .= "Ship To: \n";
$strMessageBody .= "-------- \n";
$strMessageBody .= " $s_first $s_last \n";
$strMessageBody .= " $s_addr \n";
$strMessageBody .= " $s_addr2 \n";
$strMessageBody .= " $s_city, $s_state $s_zip \n";
$strMessageBody .= " $s_phone \n";
$strMessageBody .= " \n";
$strMessageBody .= " \n";
$strMessageBody .= "Qty Price(\$) Product ID - Product Name\n";
$strMessageBody .= "===================================================================== \n";
$strMessageBody .= "$QUANTITY_1 \$$PRICE_1 $ID_1 - $NAME_1 $ADDTLINFO_1 \n";
if( $NAME_2 ) {$strMessageBody .= "$QUANTITY_2 \$$PRICE_2 $ID_2 - $NAME_2 $ADDTLINFO_2 \n";}
if( $NAME_3 ) {$strMessageBody .= "$QUANTITY_3 \$$PRICE_3 $ID_3 - $NAME_3 $ADDTLINFO_3 \n";}
if( $NAME_4 ) {$strMessageBody .= "$QUANTITY_4 \$$PRICE_4 $ID_4 - $NAME_4 $ADDTLINFO_4 \n";}
if( $NAME_5 ) {$strMessageBody .= "$QUANTITY_5 \$$PRICE_5 $ID_5 - $NAME_5 $ADDTLINFO_5 \n";}
if( $NAME_6 ) {$strMessageBody .= "$QUANTITY_6 \$$PRICE_6 $ID_6 - $NAME_6 $ADDTLINFO_6 \n";}
if( $NAME_7 ) {$strMessageBody .= "$QUANTITY_7 \$$PRICE_7 $ID_7 - $NAME_7 $ADDTLINFO_7 \n";}
if( $NAME_8 ) {$strMessageBody .= "$QUANTITY_8 \$$PRICE_8 $ID_8 - $NAME_8 $ADDTLINFO_8 \n";}
if( $NAME_9 ) {$strMessageBody .= "$QUANTITY_9 \$$PRICE_9 $ID_9 - $NAME_9 $ADDTLINFO_9 \n";}
if( $NAME_10 ){$strMessageBody .= "$QUANTITY_10 \$$PRICE_10 $ID_10 - $NAME_10 $ADDTLINFO_10 \n";}
if( $NAME_11 ){$strMessageBody .= "$QUANTITY_11 \$$PRICE_11 $ID_11 - $NAME_11 $ADDTLINFO_11 \n";}
if( $NAME_12 ){$strMessageBody .= "$QUANTITY_12 \$$PRICE_12 $ID_12 - $NAME_12 $ADDTLINFO_12 \n";}
if( $NAME_13 ){$strMessageBody .= "$QUANTITY_13 \$$PRICE_13 $ID_13 - $NAME_13 $ADDTLINFO_13 \n";}
$strMessageBody .= "===================================================================== \n";
$strMessageBody .= "SUBTOTAL: $SUBTOTAL \n";
$strMessageBody .= "TOTAL: $TOTAL \n";
$strMessageBody .= "\n";
$strMessageBody .= "FREIGHT: $SHIPPING \n";
$strMessageBody .= "\n\n";
$strMessageBody .= "Comments: \n";
$strMessageBody .= "--------- \n";
$strMessageBody .= "$comment \n";
$strMessageBody .= " \n";


if( $mode == "BOTH" || $mode == "EMAIL") {
//# Send email order to you...
$mailheaders = "From: $b_email\r\n";
$mailheaders .="X-Mailer: PHP Mail generated by:NOP Design Shopping Cart\r\n";
$subject = "New Online Order";
mail($youremail, $subject, $strMessageBody, $mailheaders);
}


if( $mode == "BOTH" || $mode == "FILE") {

$csvcomments = $comment;
if (!$CSVF = fopen($csvfilename,'a')) {
doError("Unable to open CSV file for writing. Your order has not been saved.");
exit;
}

fputs($CSVF, $string);
fputs($CSVF, "\"");
fputs($CSVF, "$today");
fputs($CSVF, "\",\"");
fputs($CSVF, "$b_first");
fputs($CSVF, "\",\"");
fputs($CSVF, "$b_last");
fputs($CSVF, "\",\"");
fputs($CSVF, "$b_addr");
fputs($CSVF, "\",\"");
fputs($CSVF, "$b_addr2");
fputs($CSVF, "\",\"");
fputs($CSVF, "$b_city");
fputs($CSVF, "\",\"");
fputs($CSVF, "$b_state");
fputs($CSVF, "\",\"");
fputs($CSVF, "$b_zip");
fputs($CSVF, "\",\"");
fputs($CSVF, "$b_phone");
fputs($CSVF, "\",\"");
fputs($CSVF, "$b_fax");
fputs($CSVF, "\",\"");
fputs($CSVF, "$b_email");
fputs($CSVF, "\",\"");
fputs($CSVF, "$s_first");
fputs($CSVF, "\",\"");
fputs($CSVF, "$s_last");
fputs($CSVF, "\",\"");
fputs($CSVF, "$s_addr");
fputs($CSVF, "\",\"");
fputs($CSVF, "$s_addr2");
fputs($CSVF, "\",\"");
fputs($CSVF, "$s_city");
fputs($CSVF, "\",\"");
fputs($CSVF, "$s_state");
fputs($CSVF, "\",\"");
fputs($CSVF, "$s_zip");
fputs($CSVF, "\",\"");
fputs($CSVF, "$s_phone");
fputs($CSVF, "\",\"");
fputs($CSVF, "$QUANTITY_1");
fputs($CSVF, "\",\"");
fputs($CSVF, "\$$PRICE_1");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ID_1");
fputs($CSVF, "\",\"");
fputs($CSVF, "$NAME_1");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ADDTLINFO_1");
fputs($CSVF, "\",\"");
fputs($CSVF, "$QUANTITY_2");
fputs($CSVF, "\",\"");
fputs($CSVF, "\$$PRICE_2");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ID_2");
fputs($CSVF, "\",\"");
fputs($CSVF, "$NAME_2");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ADDTLINFO_2");
fputs($CSVF, "\",\"");
fputs($CSVF, "$QUANTITY_3");
fputs($CSVF, "\",\"");
fputs($CSVF, "\$$PRICE_3");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ID_3");
fputs($CSVF, "\",\"");
fputs($CSVF, "$NAME_3");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ADDTLINFO_3");
fputs($CSVF, "\",\"");
fputs($CSVF, "$QUANTITY_4");
fputs($CSVF, "\",\"");
fputs($CSVF, "\$$PRICE_4");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ID_4");
fputs($CSVF, "\",\"");
fputs($CSVF, "$NAME_4");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ADDTLINFO_4");
fputs($CSVF, "\",\"");
fputs($CSVF, "$QUANTITY_5");
fputs($CSVF, "\",\"");
fputs($CSVF, "\$$PRICE_5");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ID_5");
fputs($CSVF, "\",\"");
fputs($CSVF, "$NAME_5");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ADDTLINFO_5");
fputs($CSVF, "\",\"");
fputs($CSVF, "$QUANTITY_6");
fputs($CSVF, "\",\"");
fputs($CSVF, "\$$PRICE_6");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ID_6");
fputs($CSVF, "\",\"");
fputs($CSVF, "$NAME_6");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ADDTLINFO_6");
fputs($CSVF, "\",\"");
fputs($CSVF, "$QUANTITY_7");
fputs($CSVF, "\",\"");
fputs($CSVF, "\$$PRICE_7");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ID_7");
fputs($CSVF, "\",\"");
fputs($CSVF, "$NAME_7");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ADDTLINFO_7");
fputs($CSVF, "\",\"");
fputs($CSVF, "$QUANTITY_8");
fputs($CSVF, "\",\"");
fputs($CSVF, "\$$PRICE_8");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ID_8");
fputs($CSVF, "\",\"");
fputs($CSVF, "$NAME_8");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ADDTLINFO_8");
fputs($CSVF, "\",\"");
fputs($CSVF, "$QUANTITY_9");
fputs($CSVF, "\",\"");
fputs($CSVF, "\$$PRICE_9");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ID_9");
fputs($CSVF, "\",\"");
fputs($CSVF, "$NAME_9");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ADDTLINFO_9");
fputs($CSVF, "\",\"");
fputs($CSVF, "$QUANTITY_10");
fputs($CSVF, "\",\"");
fputs($CSVF, "\$$PRICE_10");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ID_10");
fputs($CSVF, "\",\"");
fputs($CSVF, "$NAME_10");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ADDTLINFO_10");
fputs($CSVF, "\",\"");
fputs($CSVF, "$QUANTITY_11");
fputs($CSVF, "\",\"");
fputs($CSVF, "\$$PRICE_11");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ID_11");
fputs($CSVF, "\",\"");
fputs($CSVF, "$NAME_11");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ADDTLINFO_11");
fputs($CSVF, "\",\"");
fputs($CSVF, "$QUANTITY_12");
fputs($CSVF, "\",\"");
fputs($CSVF, "\$$PRICE_12");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ID_12");
fputs($CSVF, "\",\"");
fputs($CSVF, "$NAME_12");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ADDTLINFO_12");
fputs($CSVF, "\",\"");
fputs($CSVF, "$QUANTITY_13");
fputs($CSVF, "\",\"");
fputs($CSVF, "\$$PRICE_13");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ID_13");
fputs($CSVF, "\",\"");
fputs($CSVF, "$NAME_13");
fputs($CSVF, "\",\"");
fputs($CSVF, "$ADDTLINFO_13");
fputs($CSVF, "\",\"");
fputs($CSVF, "$SUBTOTAL");
fputs($CSVF, "\",\"");
fputs($CSVF, "$TOTAL");
fputs($CSVF, "\",\"");
fputs($CSVF, "$SHIPPING");
fputs($CSVF, "\",\"");
fputs($CSVF, "$comment");
fputs($CSVF, "\"\n");

fclose($CSVF);
}

//# Send email conformation to the customer.....
$mailheaders = "From: $youremail\r\n";
$mailheaders .="X-Mailer: PHP Mail generated by:NOP Design Shopping Cart\r\n";
$subject = "Order Confirmation";
mail($b_email, $subject, $strMessageBody, $mailheaders);

include($header);

echo "<h2>Thank you</h2>";
echo "Thank you for your order from our online store. You will receive a confirmation email of your order ";
echo "momentarily. Please contact us at $youremail if you have any questions or concerns.";
echo "<P>";
echo "<A HREF=\"$returnpage\" target=_top>Return Home</A>";
echo "<P>";

include($footer);

?>

Posted: Wed Jan 22, 2003 8:39 am
by patrikG
These two files, do I have to build them or are they being created by the php code? Should these be placed in the same root directory (folder) as for instance the checkout.htm ?

$header = "header.html";
$footer = "footer.html";
The above code only assigned the values "header.html" and "footer.html" to the variables $header and $footer respectively. Their raison d'ĂȘtre comes a bit further down with:

include($header);

This automatically includes a file (in this case "header.html" as this is the value given to $header).

The way that script looks, both files "header.html" and "footer.html" should be in the same directory in which is the script is running.
Return page, is the page which I want to display after the check out is copleted. Can I use in the code something like this "index.htm target=main"?
You can freely edit "header.html" and "footer.html" which both are simple HTML-code. If you edit in a href you would have what you want. That would be the simplest solution.
And no, the code you quote would produce an error.
also what's this quote?

$csvquote = "\"\"";

and mode?
// $csvquote - string value containing what to use for quotes #
// in the csv file (typically "" or \") #

\" stands for an escaped quotation mark ". This line just means that $csvquote has a value of "".
$mode = "BOTH";
// $mode - string value containing 'EMAIL', 'FILE' or #
// 'BOTH' to determine if the script should send #
// an email to you with the new order, write the #
// order to a CSV file, or do both. #

Generally, it does help reading the remarks in the code (indicated by //)

Thanks! ... still need help though ....

Posted: Thu Jan 23, 2003 2:37 am
by Bjarnat
Thanks for taking the time to explain it to me.

Unfortunatelly I cannot get the mailform.php to work, perhaps I am doing something wrong with the paths? Sorry, but I have never used any CGI-BINs nor PHP. It's seems to work fine for others...

This is the path that I have in my checkout.htm file

<form action="/cgi-bin/checkout.php" method="post" onSubmit="return CheckForm(this)">

All I get is : page not found! after placing the /cgi-bin/ in quots together with checkout.php

I know that this is a forum for php etc. but if anybody could assist me with this I would be very grateful!

Posted: Thu Jan 23, 2003 2:56 am
by evilcoder
dont execute it in your CGI-BIN folder. The beauty of php is that it can be executed from anywhere.

In fact alot of scripts i've made wont work in CGI-BIN, ask me why and i cant tell you. But try sending the info to the script in the same directory.

See if that works.

Posted: Thu Jan 23, 2003 3:14 am
by Bjarnat
Thanks!

I just did that. Now the action reads as follows:

<form action="checkout.php" method="post" onSubmit="return CheckForm(this)">

I am testing it on my computer and what happened is the download dialogue opens up asking whether I want to download the checkout.php !

I am really confused now!

Posted: Thu Jan 23, 2003 3:53 am
by twigletmac
Is PHP installed on the webserver?

Mac

Posted: Thu Jan 23, 2003 4:11 am
by Bjarnat
I am just testing it on my computer. I have not upload it yet :roll:

Posted: Thu Jan 23, 2003 5:44 am
by twigletmac
Do you have a webserver (Apache, IIS, PWS) and PHP installed on your computer?

Mac

Posted: Thu Jan 23, 2003 5:55 am
by Bjarnat
The webserver is fine and it supports the PHP etc.

I only was testing it on my computer and I didnot know I have to have PHP installed :oops: ???

Do I have to install PHP same as Java on my computer? If so, where can I get the download?

Sorry mate, but I absolutely new to PHP 8O

Thanks for your help!

Posted: Thu Jan 23, 2003 6:11 am
by twigletmac
I don't know what OS you are using, but if it is Windows give phpdev a try, it should install everything you need to test your scripts locally:
http://www.firepages.com.au/

Mac

Posted: Thu Jan 23, 2003 6:54 am
by Bjarnat
I am running Windows 98...

Thanks for the tip, eh! I visited the page but I don't which thing to download....

Posted: Thu Jan 23, 2003 7:28 am
by twigletmac
http://www.firepages.com.au/phpdev41.htm#download

You just need to click the download link next to where it says phpdev423.

Mac

Posted: Thu Jan 23, 2003 8:58 am
by Bjarnat
I did downloaded the PHP 423 and the upgrade 430.

I had the Apache / PHP running (whatever this is?) then I tested the php mailform and got the download dialogue again!

Sorry, but in this case I really do not know what am doing! 8O

Posted: Thu Jan 23, 2003 9:36 am
by twigletmac
How did you try and access the mail form? If you tried to open it directly into the browser it won't work. You need to put the file into the webserver's (Apache) root directory. The root directory is the place where the webserver will automatically expect pages to be put. According to the phpdev FAQs, for their default installation this is C:/phpdev/www. So to test that everything is installed properly put a file called phpinfo.php into that folder and place the following code in it:

Code: Select all

<?php phpinfo(); ?>
now try to go to this page in your browser:

Code: Select all

http://localhost/phpinfo.php
hopefully you should see a lot of information about the PHP installation (make sure that Apache is running before you do the test)

Mac

Posted: Wed Jan 29, 2003 2:43 am
by Bjarnat
Hi Mac!

Afer a long strugle I finally got to see the PHP mailform in action...

but I get two errors one in the "header" on line 61

and one in the footer on line 67 !

I did have a look at these lines and have no clue what could be wrong?

Any help? Thanks in advance!