Wednesday 29 May 2013

Sending Mails with attachment in Php

In php, their may arise situations where you have to send mails with attachments. So here Iam explaining how  sending mail through php library called Phpmailer.

Download phpmailer lib file from here.

Now place the below code:-

-
$msg="Thank you for your interest in our products. Your order details is attached with this mail.";


require_once 'class.phpmailer.php';

//$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

$admin="name";
$emailfrom=$adminemail;
$email_to=$receivermail;

$email =new PHPMailer(true);
$email->From      = $adminemail;
$email->FromName  = 'name';
$email->Subject   = 'your subject';
$email->Body      = $msg;
$email->AddAddress($orderdet[0]['email'] );

$file_to_attach = 'attachment.pdf';

$email->AddAttachment($file_to_attach, 'attachment.pdf' );

 $email->Send();


You can add any number of attachments by using code
$mail->AddAttachment('filepath');

Upload it on your server & check..................

Monday 6 May 2013

Reading barcodes in Php


What is a bar code reader (scanner)???
Bar code reader is a hardware pluggable into computer that sends decoded bar code strings into computer. The trick is to know how to catch that received string. With PHP (and any other web programming language) the string will be placed into focused input HTML element in browser. Thus to catch received bar code string, following must be done:

just before reading the bar code, proper input element, such as INPUT TEXT FIELD must be focused (mouse cursor is inside of the input field).
once focused, start reading the code
when the code is recognized (bar code reader usually shortly beeps), it is send to the focused input field. By default, most of bar code readers will append extra special character to decoded bar code string called CRLF (ENTER). For example, if decoded bar code is "12345AB", then computer will receive "12345AB<ENTER>". Appended character <ENTER> (or <CRLF>) emulates pressing the key ENTER causing instant submission of the HTML form:


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

    <input type="text" name="documentID" onmouseover="this.focus();">

</form>

The receiving form getbarcode.php is like:-



<?php
if(isset($_POST['documentID'])){

$barcode= htmlentities( $code ); 
}

?>

Here In $barcode variable, you will get the barcode value...


When choosing bar code reader, one should consider what types of bar codes will be read with it. Some bar codes allow only numbers, others will not have checksum, some bar codes are difficult to print with inkjet printers, some barcode readers have narrow reading pane and cannot read for example barcodes with length over 10 cm. Most of barcode readers support common barcodes, such as EAN8, EAN13, CODE 39, Interleaved 2/5, Code 128 etc.