# How to mail HTML content as the email body and a QR code attachment with PHP mail() (using TCPDF)
### First of all, declare this at the top of the page:
```=php
require_once('yourPATH/TCPDF/tcpdf_barcodes_2d.php');
```
***yourPATH*** depends on the path where you installed TCPDF. It is a dot (.) in the current file directory, and two dots (.\.) if it is on the previous directory.
### Then declare the variable you want to send html code as the text of the e-mail:
```=php
/*---------------- HTML Start -----------------*/
$html = <<<EOF
...the content...
EOF;
/*---------------- HTML End -------------------*/
```
***...the content...*** must be presented in HTML
### Then generate the QRcode:
```=php
/*---------------- QR Code Generate Start -----------------*/
$style = array(
'border' => 2,
'vpadding' => 'auto',
'hpadding' => 'auto',
'fgcolor' => array(0,0,0),
'bgcolor' => false, //array(255,255,255)
'module_width' => 1, // width of a single module in points
'module_height' => 1 // height of a single module in points
);
$barcodeobj = new TCPDF2DBarcode('$URL', 'QRCODE,M');
$file_name = "qrCode.png";
$content = $barcodeobj->getBarcodePngData();
$encoded_content = chunk_split(base64_encode($content));
/*---------------- QR Code Generate End -------------------*/
```
The variable ***\$URL*** have to be define by yourself
### The last part of the code that sends the email:
```=php
/*---------------- Sent Mail Start -----------------*/
$subject = "...Subjet...";
$subject = "=?UTF-8?B?".base64_encode($subject)."?=";
$attach_filename = date("Y-m-d") . ".html";
$emailBody = $html;
$attachment = $encoded_content;
$boundary = uniqid("");
$headers = "From: $from
To: $to
Content-type: multipart/mixed; boundary=\"$boundary\"";
$emailBody = "--$boundary
Content-type: text/html; name=$attach_filename
Content-disposition: inline; filename=$attach_filename
Content-transfer-encoding: 8bit
$emailBody
--$boundary
Content-type: image/png; name=$file_name
Content-disposition: attachment; filename=$file_name
Content-transfer-encoding: base64\r\n
$attachment
--$boundary--";
mail($email, $subject, $emailBody, $headers);
/*---------------- Sent Mail End -------------------*/
```
The ***\$from*** and ***\$to*** in the code are variables that need to be set values by yourself, and they respectively represent where they are sent from (you can customize at will) and where to send.