php send email with attachment

Solutions on MaxInterview for php send email with attachment by the best coders in the world

showing results for - "php send email with attachment"
Isaure
01 Apr 2018
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
queries leading to this page
how to send attached file email in phpphp send file to emailsend email with attachment in php using phpmailerphp add attachment to emailattachment in php mail functionsend attachment in mail phpsend attachments and html with php mailphp mailer send attachmentssend files to email phphow to add attachment in phpmailermail php send attachmentphp mail send attachment filesend attachment file and body text with email in phpphp send email attachmentsend email using phpphp email add attachmentphp html email template with attachmentsend file attachments in email phpemail attachment php 24 filephp send email with file attachmentphp mail function with attachment examplephp mail function with attachmentsend mail php with attachmenthow to send file attachment in phpphp mail 28 29 with attachment file php mail attachmentphp mail attach file from serverhow to send email with attachment using phpphp code to send email with attachmentmail function with attachment in phpphp script to send mail with attachment codephp attach file to emailfile attachment email in phpphp send email with attached filemail attachment phphow to send email from a website using phphow to get attachments to emails phpsend attachment php mailphp send emailsend attachment using smtp in phpphp send email with attachmentsend email with attachment in php wordpresssend email with attachment phpphp mail attach fileattach a file to email phpphp sending email with attachmenthow to send attachment file in mail phpphp send email smtp with attachmentsend email with attachment in phpinsert file as email body phpphp send email with attachment