create .xls file and send it in mail using php - php

My code to create xls file & attach it into mail is below:
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=test.xls");
header("Pragma: no-cache");
header("Expires: 0");
$sep = "\t";
echo "Name \t Email \t Phone \t \n ";
while($row = mysqli_fetch_array($result,MYSQLI_BOTH)){
$schema_insert = "";
$schema_insert .= "$row[0]".$sep;
$schema_insert .= "$row[1]".$sep;
$schema_insert .= "$row[2]".$sep;
$schema_insert = str_replace($sep."$", "", $schema_insert);
$schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
$schema_insert .= "\t";
print(trim(str_replace(',', " ", $schema_insert)));
print "\n";
}
file_put_contents('test.xls', $schema_insert);
$to = "ex#example.com";
$from = "ex#example.com";
$subject = "test mail";
$separator = md5(date('r', time()));
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// attachment name
$filename = "test.xls";
//$pdfdoc is PDF generated by FPDF
$attachment = chunk_split(base64_encode(file_get_contents('test.xls')));
// main header
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
// no more headers after this, we start the body! //
$body = "--".$separator.$eol;
$header .= "Content-type:text/plain; charset=iso-8859-1".$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "This is a MIME encoded message.".$eol;
// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;
// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment; filename=\"".$filename."\"".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";
if (mail($to, $subject, $body, $headers)) {
echo "mail send ... OK";
} else {
echo "mail send ... ERROR";
}
It create .xls file and mail attachment work perfect. This all thing is happen when I click on submit button.
My problem is when I click on submit button this .xls file get download. This should not happen. & The column name in .xls file echo "Name \t Email \t Phone \t \n "; is display only in that .xls file which was download on submit button click. But the .xls file that send into mail is contain only ROW data, No column name.
Can anyone suggest what is mistake in my code? And last thing, this .xls file should downloadable from mail. But I am only able to view it in new tab. No Preview, Not able to download.
Any help would be appreciated. Thanks.

i) Remove the header code to avoid download when click a button.
ii) Change the fieldname code as below,
$schema_insert = "Name \t Email \t Phone \t \n ";

Related

Creating excel report with php and sending by email

I have this php that generates an excel file for me with php reading from a database. I would like to be able to email the excel (as an attachment). The problem is that I can only get the file download but when I get the email there is no attachment
Could you help me?
When the email arrives I have only this result, without any attachment (excel file):
--90215ae30d47b3d98d4505ee5035e618
Content-Transfer-Encoding: 7bit
This is a MIME encoded message.
--90215ae30d47b3d98d4505ee5035e618
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
--90215ae30d47b3d98d4505ee5035e618
Content-Type: application/octet-stream; name="test.xls"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test.xls"
MQkwMzAyMDE4NTIzCU1HTkdQUDg0QTE4QzM1MVcJTUFHTkFOTyBESSBTQU4gTElPICAgICAgICAg
ICAgICAgICAgICAgIAlHSVVTRVBQRSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCQ==
--90215ae30d47b3d98d4505ee5035e618--
<?php
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=test.xls");
header("Pragma: no-cache");
header("Expires: 0");
$db2 = db2_connect();
$sep = "\t";
echo "Pr0001 \t Cdclie \t CodFis \t \n ";
$data = "Select t1.Pr0001, t2.CDCLIE, t1.CODFIS FROM MYLIB.ANAGR001F AS t1";
$result = db2_exec($db2, $data);
while ($row = db2_fetch_both($result)) {
$schema_insert = "";
$schema_insert .= "$row[0]".$sep;
$schema_insert .= "$row[1]".$sep;
$schema_insert .= "$row[2]".$sep;
$schema_insert = str_replace($sep."$", "", $schema_insert);
$schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
print(trim(str_replace(',', " ", $schema_insert)));
print "\n";
}
file_put_contents('test.xls', $schema_insert);
$to = "yanez25#libero.it";
$from = "robert_tr13#libero.it";
$subject = "test mail";
$separator = md5(date('r', time()));
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// attachment name
$filename = "test.xls";
$attachment = chunk_split(base64_encode(file_get_contents('test.xls')));
// main header
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
$body = "--".$separator.$eol;
$headers .= "Content-type:text/plain; charset=iso-8859-1".$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "This is a MIME encoded message.".$eol;
// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment; filename=\"".$filename."\"".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";
if (mail($to, $subject, $body, $headers)) {
echo "mail send ... OK";
} else {
echo "mail send ... ERROR";
}
?>
There is no need to reinvent the wheel when you have robust PHP libraries that do this for you.
Using PHPMailer which is one of the popular. You can send string attachment by adding it like so:
$mail->AddStringAttachment($attachment,$filename,$encoding,$type);
$encoding and $type are optional
You can check here for the full configuration and settings and if you feel you need to be part of the invention, you can either contribute code or funding.

How save a PDF file above public root and then retrieve it in PHP? (using fpdf)

I'm using fpdf to output a file to the server and then trigger an email. This works but there will be sensitive information in the pdf. How do I output the pdf to a folder above the public root? And then how do I retrieve that file again through a link?
<?php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output('/applications/doc.pdf','F');
?>
<?php
$to = "oelbaga#newworldgroup.com";
$from = "Omar <oelbaga#newworldgroup.com>";
$subject = "Test Attachment Email";
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// attachment name
$filename = "doc.pdf";
//$pdfdoc is PDF generated by FPDF
$attachment = chunk_split(base64_encode($pdf));
// main header
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
// no more headers after this, we start the body! //
$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "This is a MIME encoded message.".$eol;
// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;
// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";
// send message
if (mail($to, $subject, $body, $headers)) {
echo "mail send ... OK";
} else {
echo "mail send ... ERROR";
}
?>
Got it, although there are probably major security holes with this.
Code to output the fpdf file above the public webroot:
$pdf->Output('...physical..path.../doc.pdf','F');
Retrieve that pdf and force a download:
$oefilename = "doc.pdf";
$rootDir = realpath('/var/www/vhosts/lavaansmile.com/private/');
$fullPath = realpath($rootDir . '/' . $oefilename);
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename=' . basename($fullPath));
header('Content-Length: ' . filesize($fullPath));
#readfile($fullPath);
To get the physical path to your page you can use this:
//get real path
$path = 'NameofYourPage.php';
echo realpath($path);

php : email sending failed with more than one attachment

I am trying to implement mail functionality in php, its working fine with single attachment, but problem is when I am trying to send more than one attachment, its not working. I am using php mail() function for sending emails, I am trying to attach a PDF and an Image file. If PDF attach then Image won't attach, if Image attach then PDF won't attach. Any thoughts where I'm doing wrong?
$header .= 'From: test <noreply#test.ae>' . "\r\n";
$header .= "MIME-Version: 1.0\r\n";
$file = '1.png'
$displayname = '1.png';
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$filepdf = '1.pdf'
$displaynamepdf= '1.pdf';
$file_sizepdf = filesize($filepdf);
$handlepdf = fopen($filepdf, "r");
$contentpdf = fread($handlepdf, $file_sizepdf);
fclose($handlepdf);
$contentpdf = chunk_split(base64_encode($contentpdf));
$name = basename($file);
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$displayname."\"\r\n"; // use different content types here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$displayname."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$displaynamepdf."\"\r\n"; // use different contentpdf types here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$displaynamepdf."\"\r\n\r\n";
$header .= $contentpdf."\r\n\r\n";
$header .= "--".$uid."--";
if (mail($to, $subject, "", $header)) {
return 'sent';
} else {
return 'not sent';
}
PHPMailer is the best to use for email.
checkout some below links which will help you in future also:
File Attachments in PHP Mail with PHPMailer
php mailer attachments
attachments using phpMailer
PHPMailer Tutorial
A Simple Example : Sending Email with Attachment Using
Phpmailer
PHP send email with multiple attachments with PHPMailer with SMTP
Authentication
Sending email with multiple attachments with PHP
may this help you.
You have $file and $filepdf both set to '1.png'. Set $filepdf="1.pdf" so that the rest of the header is correct.
Here is the code for multiple attachments in mail function..
I have created the function for multiple attachment . and check this.
/*
* Function Name: sentMail
* Scope : Sent Mail Function with CC , BCC and Attachment files..
* Input : Recipient Name => $recipientName // (Required)
* Recipient MailId(Many) => $recipientMailId // (Required & Array Format)
* Subject Content => $subjectContent // (Required)
* Message Content => $messageContent // (Required)
* Sender MailId => $senderMailId // (Required)
* Sender Name(Many) => $senderName // (Required)
* Recipient CC MailId => $recipientCCMailId //(Optional & Array Format)
* Recipient BCC MailId => $recipientBCCMailId //(Optional & Array Format)
* Attachment Files => $attachmentFiles //(Optional & Array Format)
* Output : Sent mail to the Recipient.
*/
public function sentMail($recipientName,$recipientMailId,$subjectContent,$messageContent,$senderName,$senderMailId,$recipientCCMailId,$recipientBCCMailId,$attachmentFiles)
{
try
{
/*Get the Mulitple Recipient CC MailId*/
if(isset($recipientCCMailId)){
if(count($recipientCCMailId)>1){
$recipientCCMailId = implode(',',$recipientCCMailId);
}
else{
$recipientCCMailId = $recipientCCMailId[0];
}
}
/*Get the Mulitple Recipient BCC MailId*/
if(isset($recipientBCCMailId)){
if(count($recipientBCCMailId)>1){
$recipientBCCMailId = implode(',',$recipientBCCMailId);
}
else{
$recipientBCCMailId = $recipientBCCMailId[0];
}
}
/*** Mail Contents Starts ***/
$subj = $subjectContent;
$msg ="";
/*Get the Mulitple Recipient BCC MailId*/
if(count($recipientMailId)>1){
$recipientMailId = implode(',',$recipientMailId);
$msg .="Dear, <b>All</b>\r <br>";
}
else{
$recipientMailId = $recipientMailId[0];
$msg .="Dear, <b>".ucwords($user_name)."</b> \r <br>";
}
$msg .=$messageContent."\r <br><br>";
$msg .="Thank you"."\r\n\n <br>";
$msg .=$senderName."\r\n\n <br><br>";
$headers ="";
/** Get the Mulitple Attachment files and Attachment Process Starts **/
if(isset($attachmentFiles)){
$headers .= "From: ".$senderMailId."\r\n";
$headers .= "Cc: ".$recipientCCMailId."\r\n";
$headers .= "Bcc: ".$recipientBCCMailId."\r\n";
// boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$msg .= "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $msg . "\n\n";
// preparing attachments
for($i=0;$i<count($attachmentFiles);$i++)
{
if(is_file($attachmentFiles[$i]))
{
$msg .= "--{$mime_boundary}\n";
$fp = #fopen($attachmentFiles[$i],"rb");
$data = #fread($fp,filesize($attachmentFiles[$i]));
#fclose($fp);
$data = chunk_split(base64_encode($data));
$msg .= "Content-Type: application/octet-stream; name=\"".basename($attachmentFiles[$i])."\"\n" .
"Content-Description: ".basename($attachmentFiles[$i])."\n" .
"Content-Disposition: attachment;\n" . " filename=\"".basename($attachmentFiles[$i])."\"; size=".filesize($attachmentFiles[$i]).";\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
}
}
$msg .= "--{$mime_boundary}--";
}
/** Attachment Process Ends **/
else{
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=utf-8" . "\r\n";
//$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: ".$senderMailId."\r\n";
$headers .= "Cc: ".$recipientCCMailId."\r\n";
$headers .= "Bcc: ".$recipientBCCMailId."\r\n";
}
/*** Mail Contents Ends ***/
$sent_mail=mail($recipientMailId,$subj,$msg,$headers);
if($sent_mail)
{
return true;
}
else
{
return false;
}
}
catch (Exception $e)
{
getConnection('close');
echo "Caught Exception:",$e->getMessage();
}
}
i was facing the same issue. The problem is with mime boundary. Don't add "--".$uid."--"; after every attachment. Adding boundary before content type of attachment is enough.

Warning: file_get_contents(image.jpg) [function.file-get-contents]: failed to open stream: No such file or directory in php

1.Here i am trying to send my jpg image file as attachment to mail using php mail()
function.
2.My mail attachment is sending fine with word document(.doc as attachment).But,throws
errorwhen i try to send .jpg as attachment.The code i used:
<?php
/*If there is no error, send the email*/
if(isset($_POST['submit-button-name'])) {
$uname=$_POST['uname'];
$to = $_POST['mailid'];
$mobileno=$_POST['mobile'];
$location=$_POST['location'];
$from = "Urname <urname#domainname.com>";
$subject = $_POST['uname']." testing";
$separator = md5(time());
/* carriage return type (we use a PHP end of line constant)*/
$eol = PHP_EOL;
/*attachment name*/
$filename = "image.jpg";
$attachment = chunk_split(base64_encode(file_get_contents('image.jpg')));
/*main header*/
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
/*no more headers after this, we start the body!*/
$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "Check out the attachment.".$eol;
/*message*/
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;
/*attachment*/
$body .= "--".$separator.$eol;
$body .= "Content-Type: image/jpg; name=\"".$filename."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment; file=\"".$filename."\"".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";
/*send message*/
if (mail($to, $subject, $body, $headers)) {
$mail_sent=true;
echo "<font color='white'>Mail sent</font>";
$frm="urname#domainname.com";
$subj="Acknowledgement mail for Brochure form";
$msg = $_POST['username'] . ",\n\nThank you for your recent enquiry.";
$body = "Name: ".$_POST['uname'] ."\n\nEmail: ".$_POST['mailid'] ."\n\nMobile:
".$_POST['mobile'] ."\n\nLocation: ".$_POST['location'];
$headers = 'From: '.'careers#domainname.com';
mail($frm,$subj,$body,$headers);
} else {
$mail_sent=false;
}
if($mail_sent == true)
{
/*to clear the post values*/
$uname="";
$to="";
$mobileno="";
$location="";
}
else{
echo "Error,Mail not sent";
}
}
?>
3.Error being raised as:
Warning: file_get_contents(image.jpg) [function.file-get-contents]: failed to
open stream: No such file or directory in footer.php on line 48
4.I used to receive mail with the body content("Check out the attachment") and having
attachment as image.jpg with 0k(no image is opened).
5.please help.thanks in advance.Its urgent.
I thought the content type was jpeg not jpg.
Content-Type: image/jpeg;
In the section where you add the attachments.
Also the lines:
$body .= "Content-Disposition: attachment; file=\"".$filename."\"".$eol.$eol;
$body .= "--".$separator."--";
Probably should be:
$body .= "Content-Disposition: attachment;".$eol.$eol;
$body .= "--".$separator."--".$eol;
Problem being solved by giving my absolute path to-
file_get_contents('absolute path');
I used $_SERVER['DOCUMENT_ROOT'].'filename';
and it worked out successfully.
Also,i changed image/jpg to image/jpeg.
Thanks to all.
I solved my issue by giving the full absolute path for my image in this line of my code :
$attachment = chunk_split(base64_encode(file_get_contents('http://wordpress1/wp-content/themes/MyTheme/VyTCDC-brochure.jpg')));
So,you can go with your full path.Now,its working like a charm.

Mail with Attachment dosen't send HTML message

I am using a class i found to email something with attachment, yet when i send the message it dosen't appear. i'm trying to send an HTML message but even a regular one dosen't send.
Can't spot the error.
The email sends fine only the message is empty
Can someone take a look please?
Code:
<?php
class mailer{
var $email_to;
var $email_subject;
var $headers;
var $mime_boundary;
var $email_message;
//sets up variables and mail email
function mailer($email_to,$email_subject,$email_message,$headers){
$this->email_to=$email_to;
$this->email_subject=$email_subject;
$this->headers = $headers;
$semi_rand = md5(time());
$this->mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$this->headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$this->mime_boundary}\"";
$this->email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$this->mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n".
$email_message . "\n\n";
}
//adds attachment
function attach($fileatt_type,$fileatt_name,$fileatt_content){
$data = chunk_split(base64_encode($fileatt_content));
$this->email_message .= "--{$this->mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$this->mime_boundary}\n";
unset($data);
unset($file);
unset($fileatt);
unset($fileatt_type);
unset($fileatt_name);
}
//send email
function send(){
return mail($this->email_to, $this->email_subject, $this->email_message, $this->headers);
}
//extra functions to make life easier
//send email with imap
function imap_send(){
return imap_mail($this->email_to, $this->email_subject, $this->email_message, $this->headers);
}
//read file and add as attachment
function file($file){
$o=fopen($file,"rb");
$content=fread($o,filesize($file));
fclose($o);
$name=basename($file);
$type="application/octet-stream";
$this->attach($type,$name,$content);
}
//read directory and add files as attachments
function dir($dir){
$o=opendir($dir);
while(($file=readdir($o)) !==false){
if($file != "." && $file != ".."){
if(is_dir($dir."/".$file)){
$this->dir($dir."/".$file);
}else{
$this->file($dir."/".$file);
}
}
}
}
}
message populate:
$message = "<span style='color:red;'>NOTICE: test tesx..";
$message .= "test text";
$message .= "Please text test.</span>";
$message .= "If you encounter any problems please contact at contact#shibby.co.il";
calling the class:
$mailer=new mailer($mail_to,$subject,$message,"From: $from_mail");
$mailer->file($fileName);
$test=$mailer->send();
For sending mail with attachment.
<?php
//If there is no error, send the email
if(isset($_POST['ur_submit_button_name'])) {
$uname=$_POST['uname'];
$to = $_POST['mailid'];
$mobileno=$_POST['mobile'];
$location=$_POST['location'];
$from = "Yourname <Yourname#domainname.com>";
$subject = "This is the subject";
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// attachment name
$filename = "ip.zip";//store that zip file in ur root directory
$attachment = chunk_split(base64_encode(file_get_contents('ip.zip')));
// main header
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
// no more headers after this, we start the body! //
$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "This is a MIME encoded message.".$eol;
// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;
// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";
// send message
if (mail($to, $subject, $body, $headers)) {
$mail_sent=true;
echo "mail sent";
} else {
$mail_sent=false;
echo "Error,Mail not sent";
}
}
?>

Categories