1 $filename = 'myfile';
2 $path = 'your path goes here';
3 $file = $path . "/" . $filename;
4
5 $mailto = 'mail@mail.com';
6 $subject = 'Subject';
7 $message = 'My message';
8
9 $content = file_get_contents($file);
10 $content = chunk_split(base64_encode($content));
11
12 // a random hash will be necessary to send mixed content
13 $separator = md5(time());
14
15 // carriage return type (RFC)
16 $eol = "\r\n";
17
18 // main header (multipart mandatory)
19 $headers = "From: name <test@test.com>" . $eol;
20 $headers .= "MIME-Version: 1.0" . $eol;
21 $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
22 $headers .= "Content-Transfer-Encoding: 7bit" . $eol;
23 $headers .= "This is a MIME encoded message." . $eol;
24
25 // message
26 $body = "--" . $separator . $eol;
27 $body .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol;
28 $body .= "Content-Transfer-Encoding: 8bit" . $eol;
29 $body .= $message . $eol;
30
31 // attachment
32 $body .= "--" . $separator . $eol;
33 $body .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"" . $eol;
34 $body .= "Content-Transfer-Encoding: base64" . $eol;
35 $body .= "Content-Disposition: attachment" . $eol;
36 $body .= $content . $eol;
37 $body .= "--" . $separator . "--";
38
39 //SEND Mail
40 if (mail($mailto, $subject, $body, $headers)) {
41 echo "mail send ... OK"; // or use booleans here
42 } else {
43 echo "mail send ... ERROR!";
44 print_r( error_get_last() );
45 }
46
1 $filename = 'myfile';
2 $path = 'your path goes here';
3 $file = $path . "/" . $filename;
4
5 $mailto = 'mail@mail.com';
6 $subject = 'Subject';
7 $message = 'My message';
8
9 $content = file_get_contents($file);
10 $content = chunk_split(base64_encode($content));
11
12 // a random hash will be necessary to send mixed content
13 $separator = md5(time());
14
15 // carriage return type (RFC)
16 $eol = "\r\n";
17
18 // main header (multipart mandatory)
19 $headers = "From: name <test@test.com>" . $eol;
20 $headers .= "MIME-Version: 1.0" . $eol;
21 $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
22 $headers .= "Content-Transfer-Encoding: 7bit" . $eol;
23 $headers .= "This is a MIME encoded message." . $eol;
24
25 // message
26 $body = "--" . $separator . $eol;
27 $body .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol;
28 $body .= "Content-Transfer-Encoding: 8bit" . $eol;
29 $body .= $message . $eol;
30
31 // attachment
32 $body .= "--" . $separator . $eol;
33 $body .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"" . $eol;
34 $body .= "Content-Transfer-Encoding: base64" . $eol;
35 $body .= "Content-Disposition: attachment" . $eol;
36 $body .= $content . $eol;
37 $body .= "--" . $separator . "--";
38
39 //SEND Mail
40 if (mail($mailto, $subject, $body, $headers)) {
41 echo "mail send ... OK"; // or use booleans here
42 } else {
43 echo "mail send ... ERROR!";
44 print_r( error_get_last() );
45 }
1use PHPMailer\PHPMailer\PHPMailer;
2use PHPMailer\PHPMailer\Exception;
3
4$email = new PHPMailer();
5$email->SetFrom('you@example.com', 'Your Name'); //Name is optional
6$email->Subject = 'Message Subject';
7$email->Body = $bodytext;
8$email->AddAddress( 'destinationaddress@example.com' );
9
10$file_to_attach = 'PATH_OF_YOUR_FILE_HERE';
11
12$email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );
13
14return $email->Send();