PHP Send HTML Email File Attachment Using PHPs mail

PHP Send HTML Email File Attachment Using PHPs mail

In this Post We Will Explain About is PHP Send HTML Email File Attachment Using PHPs mail With Example and Demo.Welcome on – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to How to create PHP based email form with file attachmentExample

In this post we will show you Best way to implement How to Send a Confirmation Email with a File Attachment, hear for Php Send Email with Attachment – Sending Mailwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

PHP – send email with attachment file

PHP simple send mail with attachment script. This simple or custom function or source code PHP mail attachment script is simple able to send a text or plain text email send message as well as with a single data path attachment file.Below is an simple example on how we use this function to as send an simple email message with one some attached live24u.pdf file:Include the simple main script file — require_once(‘path/to/file/class.phpmailer.php’); as well as Download the PHPMailer libs or script source code from here:

Read Also:  How to Send Emails Using PHP Scripts

Source code : PHP mail attachment script

$my_file = "live24u.pdf"; // attachment file name
$path = "Your folder name"; // path of attachment file
$user_name = "Your Usrename"; // user name
$mail_to = "[email protected]"; // to eamil
$mail_sub = "Notification of attachment for user"; // subject of eamil
$body_text = "Hello ".$user_name.",\nThis demo message with file attachment. You will be notified when their review has been completed.\n Regard \n live24u Team";
$attachment_file = $path . "/" . $my_file; // path of file
$attachment_file_size = filesize($attachment_file);
$email_handle = fopen($attachment_file, "r");
$content = fread($email_handle, $attachment_file_size);
fclose($email_handle);// file close of email handle
$content = chunk_split(base64_encode($content));
$myLivetime = md5(time());// a random hash will be necessary to send mixed content
// carriage return type (we use a PHP end of line constant)
$mail_seol = PHP_EOL;
$body_message = $body_text;
// main header (multipart mandatory)
$mail_header = "From: Team <[email protected]>" . $mail_seol;
// sender eamil detail
$mail_header .= "MIME-Version: 1.0" . $mail_seol;//MIME-Version
$mail_header .= "Content-Type: multipart/mixed; boundary=\"" . $myLivetime . "\"" . $mail_seol;//Content-Type
$mail_header .= "Content-Transfer-Encoding: 7bit" . $mail_seol;//Content-Transfer-Encoding
$mail_header .= "This is a MIME encoded message." . $mail_seol;
// eamil message
$mail_header .= "--" . $myLivetime . $mail_seol;
$mail_header .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $mail_seol;
$mail_header .= "Content-Transfer-Encoding: 8bit" . $mail_seol;
$mail_header .= $body_message . $mail_seol;
// attachment
$mail_header .= "--" . $myLivetime . $mail_seol;
$mail_header .= "Content-Type: application/octet-stream; name=\"" . $my_file . "\"" . $mail_seol;
$mail_header .= "Content-Transfer-Encoding: base64" . $mail_seol;
$mail_header .= "Content-Disposition: attachment" . $mail_seol;
$mail_header .= $content . $mail_seol;
$mail_header .= "--" . $myLivetime . "--";
mail($mail_to, $mail_sub, ", $mail_header); //SEND Mail TO USER

About PHP’s native mail() function

Read Also:  php send mail attachment with Pear Mail

The attachment simple file has to be PHP uploaded first or we can use a simple file which already here exists on your any linux file or folder web server


I hope you have Got What is Sending HTML-email with Attachment Using PHP’s mail() Function And how it works.I would Like to have FeadBack From My Blog( readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article( Are Most Always Welcome.

Read Also:  PHP number_format() Function

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Laravel 6 Display Message box
  2. Read Also:  Mail send with attachment in php demo
  3. Read Also:  Black transparent rgba color code
  4. Read Also:  PHP Multiple Email Attachments with Sending Email AJAX Multiple File upload
  5. Read Also:  PHP SEND mail with Multiple Attachments
  6. Read Also:  Woocommerce Get product tags in array
  7. Read Also:  php send email with attachment example
  8. Read Also:  Difference Between Managed and Unmanaged Code in C#.NET
  9. Read Also:  PHP – Loop Between Two Dates Example
  10. Read Also:  Bootstraps JavaScript requires jQuery