Posted inProgramming / php

php send email with attachment example

Today, We want to share with you php send email with attachment example.In this post we will show you Send an email attachment with PHP, hear for program to send email with attachment in php we will give you demo and example for implement.In this post, we will learn about write a program in php to send an email along with attachment with an example.

php send email with attachment example

There are the Following The simple About php send email with attachment example Full Information With Example and source code.

As I will cover this Post with live Working example to develop smtp mail with attachment in php, so the php send email with image attachment for this example is following below.

Here’s the PHP Send an Email attachment with PHP complete code listing.

index.php

//PHP Send Email Settings
$name        = "Krunal Sisodiya";
$email       = "[email protected]";
$to          = "$name <$email>";
$from        = "Jaydeep-Sojitra ";
$subject     = "For An PHP JOB Offer Latters";
$mainMessage = "Hi dear, Below attachemnets your Offer Latters.";
$attach_files     = "./offer-latter.pdf";
$attach_filestype = "application/pdf";
$attach_filesname = "2019-offer-latter.pdf";
$headers = "From: $from";

//simple PHP File handalings
$file = fopen($attach_files, 'rb');
$data = fread($file, filesize($attach_files));
fclose($file);

// This is a PHP attaches the file
$semi_rand     = md5(time());
$data_send_mime_types = "==Multipart_Boundary_x{$semi_rand}x";
$headers      .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$data_send_mime_types}\"";
$message = "Welcome to you Pakainfo.com This is a multi-part message in MIME format.\n\n" .
"-{$data_send_mime_types}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$mainMessage  . "\n\n";

$data = chunk_split(base64_encode($data));
$message .= "--{$data_send_mime_types}\n" .
"Content-Type: {$fileatttype};\n" .
" name=\"{$fileattname}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileattname}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"-{$data_send_mime_types}-\n";

// PHP Send the email
if(mail($to, $subject, $message, $headers)) {

    echo "Good Luck, Your email was sent.";

}
else {

    echo "There was some an error for PHP sending the mail.";

}
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about php send email with attachment example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype