send attachment in mail php

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

showing results for - "send attachment in mail php"
Mario
16 Sep 2019
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
Angela
18 Oct 2020
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    }
Victoria
18 Mar 2019
1$my_file = "somefile.zip";
2$my_path = "/your_path/to_the_attachment/";
3$my_name = "Olaf Lederer";
4$my_mail = "my@mail.com";
5$my_replyto = "my_reply_to@mail.net";
6$my_subject = "This is a mail with attachment.";
7$my_message = "Hallo,rndo you like this script? I hope it will help.rnrngr. Olaf";
8mail_attachment($my_file, $my_path, "recipient@mail.org", $my_mail, $my_name, $my_replyto, $my_subject, $my_message);
Max
08 Nov 2019
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();
queries leading to this page
php send mail with attachmentsphp email add attachmentinsert file as email body phpphp mail attach file from serverattachment in phpmailersend attachment file mail phpmail function attached filephp send form information as attachment via emailphp how to attache file in mailsend attachments and html with php mailphp mail send filephp attach file to emailphp send email with attached filehow to send attachment file in mail phpphp send email with attachmentmail function with attachment in phphow to send attached file email in phphow to get attachments to emails phpmail attachment phpsend email with attachment in php using phpmailermail function display html content and attachment in phpphp contact form send email with attachmentsphp mail 28 29 with attachment file file attachment email in phpemail attachment php 24 filephp html email template with attachmentsend attachment in mail phphow to add attachment in phpmailerphp send email smtp with attachmentsend attachment file and body text with email in phpsend attachment smtp phpattachment in php mail functionsend attachment in php mail codeattach a file to email phpphp mail attach fileattachment php mailphp email file attachment codephp attachment mailphp send email attachmentphp script to send mail with attachment codephp form send email with attachmentphp mail send attachment filesend email with attachment in php wordpressphp mail add attachmentsend email using phpchange attachment in sent email in phphow to send file attachment in phphow to send email from a website using phpphp code to send email with attachmentphp mail file attachmentphp send emailphp send email with file attachmentmail attachment in php with link php add attachment to emailmail php code snipet with attachmentsend files to email phpphp mail function attachmentsimple file attachment in php mail functionphp mail function with attachmentphp sending email with attachmentsend attachment using smtp in phpphp mail 28 29 attachmentemail attachment phpphp mail attachmentphp mail with attachmentsend php file to emailattachments in php sending mailphp send file to emailphp email attachment file pathsend mail with attachment in php examplehow to send email with attachment using phpimage attachment with php mailphp mailer send attachmentssend email with attachment in phpphp mail function with attachment examplephp send attachment with emailmailjet add attachment phpsend mail php with attachmentmail php send attachmentsend file attachments in email phphow to get attachment in phpsend email with attachment phpsend attachment php mailphp send attachment with email as linksend attachment in mail php