×Welcome aboard! We are happy you are here and wish you good net-raft!

Together We Can Simplify The World

the current number of solutions:  2379
.htaccess (1x)    AJAX (13x)    ANGULARJS (161x)    ASP (1x)    ASP.NET (6x)    BACKBONE.JS (47x)    BOOTSTRAP (12x)    C# (226x)    COFFEESCRIPT (28x)    CSS (71x)    HTML (47x)    JADE (34x)    JAVA (51x)    JAVASCRIPT (432x)    JQUERY (395x)    JQUERY MOBILE (5x)    JSON (5x)    LARAVEL (27x)    MYSQL (9x)    NODEJS (162x)    ORACLE SQL (19x)    PERL (2x)    PHP (302x)    PYTHON (10x)    REACT (62x)    RUBY (25x)    RUBY ON RAILS (1x)    SHELL (2x)    SQL (90x)    SQL SERVER (3x)    TYPESCRIPT (51x)    VB.NET (33x)    W3.CSS (6x)    W3.JS (40x)    
join us

click to create your account

send email attachment php

(php send email attachment )


 viewed 8



<!DOCTYPE html>


$filename = 'logo.jpg'; // your fileame
$path = "http://xxx/xxx/"; // your path

$file = $path.$filename;
$content = file_get_contents( $file);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);

$mailto = 'xxx@gmail.com'; // mail to
$subject = 'This is a subject.';
$message = "Hello world!";

$header = "From: do-not-reply@xxx.com\r\n"; // from
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";

$nmessage = "--".$uid."\r\n";
$nmessage .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$nmessage .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$nmessage .= $message."\r\n\r\n";
$nmessage .= "--".$uid."\r\n";
$nmessage .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n";
$nmessage .= "Content-Transfer-Encoding: base64\r\n";
$nmessage .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$nmessage .= $content."\r\n\r\n";
$nmessage .= "--".$uid."--";

if (mail($mailto, $subject, $nmessage, $header)) {
echo "mail sent successfully";
} else {
echo "something went wrong";
print_r( error_get_last() );




created: 3 months ago

The power of the user (%)


Do you know a little more effective code ? Feel free to optimize ...

haven't you found what you're looking for ?
Write us your question ...
Login is not needed.

The most helpful PHP solutions
Likes Solution Technology
177 detect ie phpPHP
160 get current url phpPHP
148 Get real client country using php ?PHP
128 get meta tag phpPHP
125 detect browser phpPHP
67 How to connect to MySQL database using PHP ?PHP
61 How to split string to words using php ?PHP
59 How can I create an object using php ?PHP
53 get userdomain using phpPHP
51 get user timezone phpPHP
Check out all of PHP ...
The most viewed PHP solutions by country
Solution Country
Get real client country using php ?Cinque Terre
Get real client country using php ?Cinque Terre
How to insert the image to body of an php email using php ?Cinque Terre
How to get title tag using php ?Cinque Terre
Get real client country using php ?Cinque Terre
Get real client country using php ?Cinque Terre
detect speed internet phpCinque Terre
how to create a function for drop table using php ?Cinque Terre
How to set sessions in php ?Cinque Terre
Get real client country using php ?Cinque Terre