logo

Extra Block Types (EBT) - New Layout Builder experience❗

Extra Block Types (EBT) - styled, customizable block types: Slideshows, Tabs, Cards, Accordions and many others. Built-in settings for background, DOM Box, javascript plugins. Experience the future of layout building today.

Demo EBT modules Download EBT modules

❗Extra Paragraph Types (EPT) - New Paragraphs experience

Extra Paragraph Types (EPT) - analogical paragraph based set of modules.

Demo EPT modules Download EPT modules

Scroll

Email and name validation in PHP

22/02/2025, by Anonymous (not verified)

Hello, dear ones!

I have a script and I need it to check the email and username before accepting an order. Thank you in advance!

 

 

<h1>Order Processing</h1>
<?php

require_once realpath(dirname(__FILE__) . '/../cms/local.php');
function send_mail($emailaddress, $fromaddress, $emailsubject, $body, $attachments=false){
    $eol="\n";
    $mime_boundary=md5(time());
# Common Headers    $headers  = '';
$headers .= 'From: '.$fromaddress.$eol;    $headers .= 'Reply-To: '.$fromaddress.$eol;
$headers .= 'Return-Path: '.$fromaddress.$eol;    // these two to set reply address
$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;    $headers .= "X-Mailer: PHP v".phpversion().$eol;
// These two to help avoid spam-filters    $headers .= 'Bcc: '.EMAILS_ORDER.$eol;    # Boundary for marking the split & Multitype Headers
$headers .= 'MIME-Version: 1.0'.$eol;    $headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg = "";    if ($attachments !== false)          {
for($i=0; $i < count($attachments); $i++)    {
if (is_file($attachments[$i]["file"]))    {
# File for Attachment    //$file_name = substr($attachments[$i]["file"], (strrpos($attachments[$i]["file"], "/")+1));
$file_name = basename($attachments[$i]["name"]);    $handle=fopen($attachments[$i]["file"], 'rb');
$f_contents=fread($handle, filesize($attachments[$i]["file"]));    $f_contents=chunk_split(base64_encode($f_contents));

// Encode The Data For Transition using base64_encode();    fclose($handle);
# Attachment    $msg .= "--".$mime_boundary.$eol;

$msg .= "Content-Type: ".$attachments[$i]["content_type"]."; name=\"".$file_name."\"".$eol;        $msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
//$msg .= "Content-Disposition: attachment;".$eol;        //
$msg .= "            filename=\"".$file_name."\"".$eol.$eol;
$msg .= $f_contents.$eol.$eol;            }
}                }
# Setup for text OR html                $msg .= "Content-Type: multipart/alternative".$eol;        /*
# Text Version                $msg .= "--".$mime_boundary.$eol;

$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;                $msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$msg .= strip_tags(str_replace("<br>", "\n", $body)).$eol.$eol;                */
# HTML Version                $msg .= "--".$mime_boundary.$eol;    $msg .= "Content-Type: text/html; charset=windows-1251".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol;                $msg .= $body.$eol.$eol;

# Finished                $msg .= "--".$mime_boundary."--".$eol.$eol;  // finish with two eol's for better security. see Injection.

# SEND THE EMAIL
ini_set(sendmail_from,$fromaddress);  // the INI lines are to force the From Address to be used !
$result = mail($emailaddress, $emailsubject, $msg, $headers); ini_restore(sendmail_from); return $result; } if ( isset($_POST['Full Name']) ) { $fio = $_POST['Full Name']; $reg = $_POST['Region']; $city = $_POST['City']; $phone = $_POST['Phone']; $email = $_POST['Email']; $addres = $_POST['Delivery Address']; $com = $_POST['Order Comment']; $group1 = $_POST['group1']; $to = $email; $from = '"Website '.$_SERVER['SERVER_NAME'].'" '; // email subject $subject = 'Order from website '.$_SERVER['SERVER_NAME'].' on '.date('d-m-Y H:i'); // email body text $message = " Order Confirmation

Your order from ".date('d.m.Y H:i')."

Customer Information:
Full Name $fio
Region $reg
City $city
Contact Phone $phone
Email $email
Delivery Address $addres
Payment Method $group1
Order Comment: $com

Order Contents:

"; if ($_SESSION['cart']) { $totalArray = array(); $uniqueArray = array_unique($_SESSION['cart']); // remove duplicate items // Final count of product IDs and their quantities foreach ($uniqueArray as $key) { foreach ( $_SESSION['cart'] as $k => $v ) { $totalArray[$v] = ( $v == $key ) ? $totalArray[$v] + 1 : $totalArray[$v] ; } } } $DB = new PDO ('sqlite:'.$_SERVER['DOCUMENT_ROOT'].'/minicms.sqlite'); $r = $DB->query('SELECT * FROM catalog_items')->fetchAll(); $message .= ''; $totalPrice = 0; $MoneyUnit = array('rub' => 'rub', 'dollar' => '$' ); foreach ($r as $recId => $dataArr) { if ( isset($totalArray[$dataArr['id']]) ) { $totalPrice += $dataArr['price']*$totalArray[$dataArr['id']]; $message .= "". "". "". "". "";                        "</tr>";
                    }
                }
    $message .= '<tr class="footerTable">
        <td style="text-align: right; font-weight: bold" colspan="2">Total Cost</td>
        <td id="cashe" style="font-weight: bold" align="center" colspan="2">'.$totalPrice.'</td>
    </tr>
    </table>';
    } else {
        $message .= '<h3>There are no items in the cart</h3>';
    }
    $message .= "</body>
            </html>
            ";
           
            if ( send_mail($to, $from, $subject, $message) ) {
?>
                <br />
                <h2>Your order has been accepted</h2>
                <p>An email with the order details has been sent to the address provided during checkout.</p>
                <p>Our manager will contact you shortly to confirm the details.</p>
                <br /><br /><br />
                <h2>Customer Information</h2>
                <?=$message ?>
               
<?php    
                unset($_SESSION['cart']);               
            } else {
?>
                <h2>Error sending message!</h2>
                <p>Please contact the website developers!</p>
<?php                
            }
} else {?>
   
<p>Please check that all fields are filled out correctly.</p>
<p>Accurate contact information: phone number and email address are necessary for us to process your order promptly.</p>

<form id="orderSend" action="" method="POST">
    <input type="text" size="70" name="Full Name" value="Full Name" /><br />
    <input type="text" size="70" name="Region" value="Region" /><br />
    <input type="text" size="70" name="City" value="City" /><br />
    <input type="text" size="70" name="Phone" value="Phone" /><br />
    <input type="text" size="70" name="Email" value="Email" /><br />
    <input type="text" size="70" name="Delivery Address" value="Delivery Address" /><br />
    <textarea name="Order Comment" cols="54" rows="7">Order Comment</textarea><br />
    <br />
    <input type="radio" name="paymentMethod" value="Cash on delivery" />Cash on delivery<br />
    <input type="radio" name="paymentMethod" value="Payment via Sberbank" />Payment via Sberbank<br />
    <input type="radio" name="paymentMethod" value="Bank transfer" />Bank transfer</br>
   
    <input type="submit" value="Complete Order" id="sendOrdering" />
   
</form>


<?php } ?>
Product Name Quantity Price per Unit, rub Total Price, rub
".$dataArr['name']."".$totalArray[$dataArr['id']]."".$dataArr['price']."".$dataArr['price']*$totalArray[$dataArr['id']]."