Jump to content

Automated invoice help


CrossY

Recommended Posts

Hey PHPFreaks,

 

Back with another newbie question (I reckon).

 

Currently i'm using this form: http://www.kartalin.nl/bestellen.php (Dutch).

 

 

Upon entering your information you will be send to the confirmation page, where an automated email will be send to you (with the data you entered) and to me (so I can tell an order has been placed).

 

After that, i'll have to create a invoice and send it to them, a tedious job that i'd much rather have automatized. Even though its already rather obvious what has been ordered, its just that i'm lacking 2 things:

 

 

1. I need the invoice number to be identical and in a sequence, so K001, K002, K003 etc. Since i'm currently only using basic HTML in this email, I don't know if that's possible, or how to do it.

 

2. People pick both a product, and their pick of choice on how to ship the product. There are quite alot of combinations, so for that i'll probably need some tool (called a calculater? haha..) that actually adds those 2 prices and calculates the total amount to be payed. No VAT calculator is needed.

 

 

Also i've found the current HTML I send in via the mail to be quite dodgy. I cant use special characters for example, therefor it might be good to have these 2 options in a system that actually allows for full HTML aswell. This could come in handy when I need to create a table to sum those different prices up.

 

 

 

Currently using this code:

<?php

// your email address
$youremail = "my@email.com";

// field validation
if ($naam=="" || $achternaam=="")

{
print ("Alle velden moeten worden ingevuld!");
}

else {

// send email
$headers = "From: \"$naam\" <$email>\n";
$subject = "Bestelling Kartalin";
$from    = "Kartalin.nl <info@kartalin.nl>";
$message = "Dear $name<br /></br />


blabla your order has been received etc.

";

mail ("$youremail", $subject, $message, "From: $from\nContent-Type: text/html; charset=iso-8859-1");

mail ("$email", $subject, $message, "From: $from\nContent-Type: text/html; charset=iso-8859-1");

} 
?>

 

 

I'd appreciate it a lot if someone could help me with this!

 

Link to comment
Share on other sites

The code in the OP is used as confirmation, so it sends the email with data they've entered themselves.

 

This is the order page itself:

 

<?php
//Values for select lists
$productList = array(
    'Proefmonster EUR 2,95' => 'Proefmonster € 2,95',
    '1x 125gr. kartalin EUR 30,00' => '1x 125gr. kartalin € 30,00',
    '2x 125gr. kartalin EUR 56,00' => '2x 125gr. kartalin € 56,00',
    '3x 125gr. kartalin EUR 80,00' => '3x 125gr. kartalin € 80,00'
    );

$landList = array(
    'Nederland' => 'Nederland',
    'Belgie' => 'België',
    'Overig (zie opmerkingen)' => 'Overig (zie opmerkingen)'
    );

$verzendingList = array(
    'Proefmonster (geen extra verzendkosten)' => 'Proefmonster (geen extra verzendkosten)',
    'NL via DHL (binnen 2 a 3 werkdagen) EUR 4,95' => 'NL Via DHL (binnen 2 á 3 werkdagen) € 4,95',
    'NL via TNT (volgende werkdag) EUR 6,75' => 'NL Via TNT (volgende werkdag) € 6,75',
    'BE Via TNT (binnen 1 a 2 werkdagen) EUR 8,70' => 'BE Via TNT (binnen 1 a 2 werkdagen) € 8,70'
    );

function createSelectOptions($optionList, $selectedValue=false)
{
    foreach($optionList as $value=>$text)
    {
        $selected = ($value===$selectedValue) ? ' selected="selected"' : '';
        echo "<option value=\"{$value}\"{$selected}>{$text}</option>\n";
    }
}

function is_email($email) 
{
    $formatTest = '/^[\w!#$%&\'*+\-\/=?^`{|}~]+(\.[\w!#$%&\'*+\-\/=?^`{|}~]+)*@[a-z\d]([a-z\d-]{0,62}[a-z\d])?(\.[a-z\d]([a-z\d-]{0,62}[a-z\d])?)*\.[a-z]{2,6}$/i';
    $lengthTest = '/^(.{1,64})@(.{4,255})$/';
    return (preg_match($formatTest, $email) && preg_match($lengthTest, $email));
}

//Create initial variables
$naam        = (isset($_POST['naam'])) ? trim($_POST['naam']) : '';
$achternaam  = (isset($_POST['achternaam'])) ? trim($_POST['achternaam']) : '';
$email       = (isset($_POST['email'])) ? trim($_POST['email']) : '';
$straat      = (isset($_POST['straat'])) ? trim($_POST['straat']) : '';
$huisnummer  = (isset($_POST['huisnummer'])) ? trim($_POST['huisnummer']) : '';
$postcode    = (isset($_POST['postcode'])) ? trim($_POST['postcode']) : '';
$plaats      = (isset($_POST['plaats'])) ? trim($_POST['plaats']) : '';
$land        = (isset($_POST['land'])) ? trim($_POST['land']) : '';
$telefoon    = (isset($_POST['telefoon'])) ? trim($_POST['telefoon']) : '';
$product     = (isset($_POST['product'])) ? trim($_POST['product']) : '';
$verzending  = (isset($_POST['verzending'])) ? trim($_POST['verzending']) : '';
$korting     = (isset($_POST['korting'])) ? trim($_POST['korting']) : '';
$opmerkingen = (isset($_POST['opmerkingen'])) ? trim($_POST['opmerkingen']) : '';
$errorText = '';

if(isset($_POST['naam']))
{
    //User submitted data - perform validation
    $errors = array();

    if(empty($naam)) { $errors[] = "Naam is verplicht."; }
    if(empty($achternaam)) { $errors[] = "Achternaam is verplicht."; }
    if(empty($email)) { $errors[] = "Email is verplicht."; }
    else if(!is_email($email))  { $errors[] = "Ongeldig emailadres."; }
    if(empty($straat)) { $errors[] = "Adres is verplicht."; }
    if(empty($huisnummer)) { $errors[] = "Huisnummer is verplicht."; }
    if(empty($postcode)) { $errors[] = "Postcode is verplicht."; }
    if(empty($plaats)) { $errors[] = "Woonplaats is verplicht."; }
    if(empty($telefoon)) { $errors[] = "Telefoonnummer is verplicht."; }
    if(empty($product)) { $errors[] = "Maak een productkeuze."; }
    if(empty($verzending)) { $errors[] = "Kies een verzendmethode."; }


    if(count($errors)>0)
    {
        $errorText .= "<span style=\"color:#ff0000;\">";
        $errorText .= "De volgende fout(en) zijn opgetreden:<ul>\n";
        foreach($errors as $errorMsg)
        {
            $errorText .= "<li>$errorMsg</li>";
        }
        $errorText .= "</ul></span>";
    }
    else
    {
        //Form validation passed include page to process the data
        include('ordercomplete.php');
        exit();
    }
}

?>

 

The form itself looks like this:

<?php echo $errorText; ?>
<form action="" method="post">
<table border="0">
      <tr>
            <td align="right">Voornaam:</td>
            <td><input name="naam" size="25" style='width: 276px;' type="text" value="<?php echo $naam; ?>" /></td>
      </tr>
      <tr>
            <td align="right">Achternaam:</td>
            <td><input name="achternaam" size="25" style='width: 276px;' type="text" value="<?php echo $achternaam; ?>" /></td>
      </tr>
      <tr>
            <td align="right">Straatnaam & huisnummer:</td>
            <td>
                <input name="straat" size="25" style='width: 229px;' type="text" value="<?php echo $straat; ?>" /> <input name="huisnummer" size="25" style='width: 40px;' type="text" value="<?php echo $huisnummer; ?>" />
            </td>
      </tr>
      <tr>
            <td align="right">Postcode & woonplaats:</td>
            <td><input name="postcode" size="25" maxlength="7" type="text" style='width: 56px;' value="<?php echo $postcode; ?>" /> <input name="plaats" size="25" type="text" style='width: 213px;' value="<?php echo $plaats; ?>" /></td>
      </tr>
      <tr>
            <td align="right">Land:</td>
            <td><select name="land" size="1" style='width: 280px;'>
                <?php createSelectOptions($landList, $land); ?>
                </select>
            </td>
      </tr>
       <tr>
            <td align="right">Email:</td>
            <td><input name="email" size="25" type="text" style='width: 276px;' value="<?php echo $email; ?>" /></td>
      </tr>
      <tr>
            <td align="right">Telefoon:</td>
            <td><input name="telefoon" size="12" type="text" value="<?php echo $telefoon; ?>" /></td>
      </tr>
      <tr>
            <td align="right">Ik bestel:</td>
            <td><select name="product" size="4" style='width: 280px;'>
                <?php createSelectOptions($productList, $product); ?>
                </select>
            </td>
      </tr>
      <tr>
            <td align="right">Verzendwijze:</td>
            <td><select name="verzending" size="4" style='width: 280px;'>
                <?php createSelectOptions($verzendingList, $verzending); ?>
                </select>
            </td>
      </tr>
      <tr>
            <td align="right">Kortingscode:</td>
            <td><input name="korting" size="25" style='width: 276px;' type="text" value="<?php echo $korting; ?>" /></td>
      </tr>
      <tr>
            <td align="right">Opmerkingen:</td>
            <td><textarea name="opmerkingen" rows="5" cols="29" style='width: 276px;'><?php echo $opmerkingen; ?></textarea></td>
      </tr>
      <tr>
            <td></td>
            <td><input name="verzenden" value="Verzenden" type="submit"> <input type="reset" value="Opnieuw"></td>
      </tr>
</table>
</form>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.