codice:
	<?php
function cbd_random_string($typeString, $intLength = 6) {
	//if($typeString==1){ $validCharacters = "abcdefghijklmnopqrstuxyvwz0123456789ABCDEFGHIJKLMNOPQRSTUXYVWZ";}
	if($typeString==1){ $validCharacters = "1234567890";}
	/*if($typeString==3){ $validCharacters = "abcdefghijklmnopqrstuxyvwz";}
	if($typeString==4){ $validCharacters = "ABCDEFGHIJKLMNOPQRSTUXYVWZ";}*/
	$validCharNumber = strlen($validCharacters);
	$result = "";
	for ($i = 0; $i < $intLength; $i++) {
		$index = mt_rand(0, $validCharNumber - 1);
		$result .= $validCharacters[$index];
	}
	return $result;
}
//*** END FUNCTION cbd_random_string
	$data = time();
	$email = $_GET['email'];
	$buono =  cbd_random_string(1);
//genero il file pdf
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
    //Page header
    public function Header() {
        // Logo
        $image_file = K_PATH_IMAGES.'logo_example.jpg';
        $this->Image($image_file, 10, 10, 0, '', 'JPG', '', 'T', false, 72, '', false, false, 0, false, false, false);
        // Set font
        $this->SetFont('helvetica', 'B', 20);
        // Title
        $this->Cell(0, 15, '', 0, false, 'C', 0, '', 0, false, 'M', 'M');
    }
    // Page footer
    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont('helvetica', 'I', 8);
        // Page number
        $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
    }
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 003');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 061', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set font
$pdf->SetFont('helvetica', '', 12);
// add a page
$pdf->AddPage();
/* NOTE:
 * *********************************************************
 * You can load external XHTML using :
 *
 * $html = file_get_contents('/path/to/your/file.html');
 *
 * External CSS files will be automatically loaded.
 * Sometimes you need to fix the path of the external CSS.
 * *********************************************************
 */
// define some HTML content with style
$html = <<<EOF
<style type="text/css">
    h1 {
        color: navy;
        font-family: times;
        font-size: 24pt;
        text-decoration: underline;
    }
    .testo{
	font-family: helvetica;
	font-size: 16px;
	text-align: justify;
	line-height: 18px;
    }
    
    table.first {
        color: #003300;
        font-family: helvetica;
        font-size: 8pt;
        border-left: 3px solid red;
        border-right: 3px solid #FF00FF;
        border-top: 3px solid green;
        border-bottom: 3px solid blue;
        background-color: #ccffcc;
    }
    td {
        border: 2px solid blue;
        background-color: #ffffee;
    }
    td.second {
        border: 2px dashed green;
    }
	div.wrapper{
		position:relative;
	
		margin-top:200px;
		}
    div.contenuto {
		position:relative;
	margin-top:800px;
	margin-left: 20px;
	margin-bottom: 20px;
	
    }
	 div.contenuto1 {
	margin-top:30px;
	margin-left: 20px;
    }
	.txtBuono
	{
		position:absolute;
		top:450px;
		left:300px;
		color:red;
		z-index:1000;
	}
	.testo
	{
		font-size:16px;
	}
</style>
<div class="wrapper">
<div class="contenuto">
Gentile Cliente, grazie per esserti registrato nel nostro sito. In questo modo avrai l'opportunità 
 di ricevere la nostra newsletter, partecipare alle nostre promozioni e tanto altro ancora.
Ti chiediamo di lasciare una tua opinione sui nostri prodotti scrivendo una recensione.
Inoltre potrai accedere a  e conoscere gente con la tua stessa
 passione, scoprire le news dal mondo dell'integrazione e molto altro ancora.</p></div>
<div class="contenuto1">
MAIL: $email</p>
CODICE PROMOZIONALE: $buono</p>
</div>
</div>
EOF;
// -- set new background ---
// get the current page break margin
$bMargin = $pdf->getBreakMargin();
// get current auto-page-break mode
$auto_page_break = $pdf->getAutoPageBreak();
// disable auto-page-break
$pdf->SetAutoPageBreak(false, 0);
// set bacground image
$img_file = K_PATH_IMAGES.'sfondoBuono.jpg';
$pdf->Image($img_file, 10, 40, 190, 100, '', '', '', false, 72, '', false, false, 0);
// restore auto-page-break status
$pdf->SetAutoPageBreak($auto_page_break, $bMargin);
// set the starting point for the page content
$pdf->setPageMark();
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
// reset pointer to the last page
$pdf->lastPage();
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_061.pdf', 'I');
		
		
			
	$sqlCodice = "INSERT INTO buono_sconto (id_utente,numero,data_emissione) VALUES ('$id ','$buono','$data')";
	$resCodice = mysql_query($sqlCodice);
		
			$content = "Benvenuto $_POST[username],\r\n";
			$content .= "ecco il tuo buono sconto:\r\n\r\n";
			$content .= $buono;
   			
			mail($row['email'], "Iscrizione al sito...", $content, "From: Vs<users@users.it>");
			
			
			
?>