Send Attachments With PHP Mail()?

Call Now
WhatsApp
Message Now

Details

To send an email with attachment we need to use the multipart/mixed MIME type that specifies that mixed types will be included in the email. Moreover, we want to use multipart/alternative MIME type to send both plain-text and HTML version of the email.Have a look at the example:

$filename = 'file';
$path = 'your path goes here';
$file = $path . "/" . $filename;

$mailto = 'to@mail.com';
$subject = 'Subject';
$message = 'My message';

$content = file_get_contents($file);
$content = chunk_split(base64_encode($content));

// a random hash will be necessary to send mixed content
$separator = md5(time());

// carriage return type (RFC)
$eol = "\r\n";

// main header (multipart mandatory)
$headers = "From: name <from@mail.com>" . $eol;
$headers .= "MIME-Version: 1.0" . $eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
$headers .= "Content-Transfer-Encoding: 7bit" . $eol;
$headers .= "This is a MIME encoded message." . $eol;

// message
$body = "--" . $separator . $eol;
$body .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol;
$body .= "Content-Transfer-Encoding: 8bit" . $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;
$body .= $content . $eol;
$body .= "--" . $separator . "--";

//SEND Mail
if (mail($mailto, $subject, $body, $headers)) {
echo "mail send ... OK"; // or use booleans here
} else {
echo "mail send ... ERROR!";
print_r( error_get_last() );
}

Related Updates

Payment Gateway

A Payment Gateway Is A Merchant Service Provided By An E-commerce Application Service Provider That Authorizes Credit Card Or Direct Payments Processing For E-businesses, Online Retailers, Bricks And Clicks, Or Traditional Brick And Mortar. The Payment Gateway May Be Provided By A Bank To Its Customers, But Can Be Provided By A Specialised Financial Service Provider As A Separate Service, Such As A Payment Service Provider.A Payment Gateway Facilitates A Payment Transaction By The Transfer Of I Continue

Payment Gateway Integration Into A Website

In The Online Business Creation Process The First Ideas Are Related To The Business Type, What To Do, What To Sell, And Right There The Question Came Out. How To Charge For Your Services And/or Products? How To Allow Customers To Pay Online Using Their Credit Cards Or Checks? The Answer Couldn't Be Easier; You Need A Merchant Account With The Ability Of Accepting Online Payments Through A Payment Gateway.There Is Where We Can Help You, We Have Hundreds Of Websites Integrated With Almost Any Onl Continue

How To Write Subquery In Codeigniter Active Record

CodeIgniter Active Records Do Not Currently Support Sub-queries, However I Use The Following Approach: $this->db->select('id');$this->db->from('table');$where_clause = $this->db->_compile_select(false,true);$this->db->_reset_select();#Create Main Query$this->db->select('*');$this->db->from('table1');$this->db->where("`id` NOT IN ($where_clause)", NULL, FALSE);Return $this->db->get('',null,null,true); _compile_select() And _reset_ Continue


Request For Quotation
Location
Shopali Building , Ghandhi Chowk,
Dhrol - 361210
Gujarat (India)
MoTuWeThFrSaSu
Open11:00 AM To 7:00 PM
Ique Infotech
All rights reserved - Copyright © 2024 - Powered by
4allBIZ
Request a Call Back!