Guest User

Untitled

a guest
Nov 8th, 2018
2,429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.07 KB | None | 0 0
  1. $to = "xxx";
  2. $subject = "Subject" ;
  3. $message = 'Example message with <b>html</b>';
  4. $headers = 'MIME-Version: 1.0' . "rn";
  5. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
  6. $headers .= 'From: xxx <xxx>' . "rn";
  7. mail($to,$subject,$message,$headers);
  8.  
  9. use PHPMailerPHPMailerPHPMailer;
  10. use PHPMailerPHPMailerException;
  11.  
  12. $email = new PHPMailer();
  13. $email->SetFrom('you@example.com', 'Your Name'); //Name is optional
  14. $email->Subject = 'Message Subject';
  15. $email->Body = $bodytext;
  16. $email->AddAddress( 'destinationaddress@example.com' );
  17.  
  18. $file_to_attach = 'PATH_OF_YOUR_FILE_HERE';
  19.  
  20. $email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );
  21.  
  22. return $email->Send();
  23.  
  24. $filename = 'myfile';
  25. $path = 'your path goes here';
  26. $file = $path . "/" . $filename;
  27.  
  28. $mailto = 'mail@mail.com';
  29. $subject = 'Subject';
  30. $message = 'My message';
  31.  
  32. $content = file_get_contents($file);
  33. $content = chunk_split(base64_encode($content));
  34.  
  35. // a random hash will be necessary to send mixed content
  36. $separator = md5(time());
  37.  
  38. // carriage return type (RFC)
  39. $eol = "rn";
  40.  
  41. // main header (multipart mandatory)
  42. $headers = "From: name <test@test.com>" . $eol;
  43. $headers .= "MIME-Version: 1.0" . $eol;
  44. $headers .= "Content-Type: multipart/mixed; boundary="" . $separator . """ . $eol;
  45. $headers .= "Content-Transfer-Encoding: 7bit" . $eol;
  46. $headers .= "This is a MIME encoded message." . $eol;
  47.  
  48. // message
  49. $body = "--" . $separator . $eol;
  50. $body .= "Content-Type: text/plain; charset="iso-8859-1"" . $eol;
  51. $body .= "Content-Transfer-Encoding: 8bit" . $eol;
  52. $body .= $message . $eol;
  53.  
  54. // attachment
  55. $body .= "--" . $separator . $eol;
  56. $body .= "Content-Type: application/octet-stream; name="" . $filename . """ . $eol;
  57. $body .= "Content-Transfer-Encoding: base64" . $eol;
  58. $body .= "Content-Disposition: attachment" . $eol;
  59. $body .= $content . $eol;
  60. $body .= "--" . $separator . "--";
  61.  
  62. //SEND Mail
  63. if (mail($mailto, $subject, $body, $headers)) {
  64. echo "mail send ... OK"; // or use booleans here
  65. } else {
  66. echo "mail send ... ERROR!";
  67. print_r( error_get_last() );
  68. }
  69.  
  70. $file = $path.$filename;
  71. $content = file_get_contents( $file);
  72. $content = chunk_split(base64_encode($content));
  73. $uid = md5(uniqid(time()));
  74. $name = basename($file);
  75.  
  76. // header
  77. $header = "From: ".$from_name." <".$from_mail.">rn";
  78. $header .= "Reply-To: ".$replyto."rn";
  79. $header .= "MIME-Version: 1.0rn";
  80. $header .= "Content-Type: multipart/mixed; boundary="".$uid.""rnrn";
  81.  
  82. // message & attachment
  83. $nmessage = "--".$uid."rn";
  84. $nmessage .= "Content-type:text/plain; charset=iso-8859-1rn";
  85. $nmessage .= "Content-Transfer-Encoding: 7bitrnrn";
  86. $nmessage .= $message."rnrn";
  87. $nmessage .= "--".$uid."rn";
  88. $nmessage .= "Content-Type: application/octet-stream; name="".$filename.""rn";
  89. $nmessage .= "Content-Transfer-Encoding: base64rn";
  90. $nmessage .= "Content-Disposition: attachment; filename="".$filename.""rnrn";
  91. $nmessage .= $content."rnrn";
  92. $nmessage .= "--".$uid."--";
  93.  
  94. if (mail($mailto, $subject, $nmessage, $header)) {
  95. return true; // Or do something here
  96. } else {
  97. return false;
  98. }
  99.  
  100. // Create the message
  101. $message = Swift_Message::newInstance()
  102. ->setSubject('Your subject')
  103. ->setFrom(array('webmaster@mysite.com' => 'Web Master'))
  104. ->setTo(array('receiver@example.com'))
  105. ->setBody('Here is the message itself')
  106. ->attach(Swift_Attachment::fromPath('myPDF.pdf'));
  107.  
  108. //send the message
  109. $mailer->send($message);
  110.  
  111. <?php
  112. //define the receiver of the email
  113. $to = 'youraddress@example.com';
  114. //define the subject of the email
  115. $subject = 'Test email with attachment';
  116. //create a boundary string. It must be unique
  117. //so we use the MD5 algorithm to generate a random hash
  118. $random_hash = md5(date('r', time()));
  119. //define the headers we want passed. Note that they are separated with rn
  120. $headers = "From: webmaster@example.comrnReply-To: webmaster@example.com";
  121. //add boundary string and mime type specification
  122. $headers .= "rnContent-Type: multipart/mixed; boundary="PHP-mixed-".$random_hash.""";
  123. //read the atachment file contents into a string,
  124. //encode it with MIME base64,
  125. //and split it into smaller chunks
  126. $attachment = chunk_split(base64_encode(file_get_contents('attachment.zip')));
  127. //define the body of the message.
  128. ob_start(); //Turn on output buffering
  129. ?>
  130. --PHP-mixed-<?php echo $random_hash; ?>
  131. Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
  132.  
  133. --PHP-alt-<?php echo $random_hash; ?>
  134. Content-Type: text/plain; charset="iso-8859-1"
  135. Content-Transfer-Encoding: 7bit
  136.  
  137. Hello World!!!
  138. This is simple text email message.
  139.  
  140. --PHP-alt-<?php echo $random_hash; ?>
  141. Content-Type: text/html; charset="iso-8859-1"
  142. Content-Transfer-Encoding: 7bit
  143.  
  144. <h2>Hello World!</h2>
  145. <p>This is something with <b>HTML</b> formatting.</p>
  146.  
  147. --PHP-alt-<?php echo $random_hash; ?>--
  148.  
  149. --PHP-mixed-<?php echo $random_hash; ?>
  150. Content-Type: application/zip; name="attachment.zip"
  151. Content-Transfer-Encoding: base64
  152. Content-Disposition: attachment
  153.  
  154. <?php echo $attachment; ?>
  155. --PHP-mixed-<?php echo $random_hash; ?>--
  156.  
  157. <?php
  158. //copy current buffer contents into $message variable and delete current output buffer
  159. $message = ob_get_clean();
  160. //send the email
  161. $mail_sent = @mail( $to, $subject, $message, $headers );
  162. //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
  163. echo $mail_sent ? "Mail sent" : "Mail failed";
  164. ?>
  165.  
  166. $email = new PHPMailer();
  167. $email->From = 'from@somedomain.com';
  168. $email->FromName = 'FromName';
  169. $email->Subject = 'Subject';
  170. $email->Body = 'Body';
  171. $email->AddAddress( 'to@somedomain.com' );
  172. $email->AddAttachment( "/path/to/file" , "filename.ext", 'base64', 'application/octet-stream' );
  173. $email->Send();
  174.  
  175. if (isset($_POST['submit'])) {
  176. $mailto = $_POST["mailTo"];
  177. $from_mail = $_POST["fromEmail"];
  178. $replyto = $_POST["fromEmail"];
  179. $from_name = $_POST["fromName"];
  180. $message = $_POST["message"];
  181. $subject = $_POST["subject"];
  182.  
  183. $filename = $_FILES["fileAttach"]["name"];
  184. $content = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
  185.  
  186. $uid = md5(uniqid(time()));
  187. $name = basename($file);
  188. $header = "From: " . $from_name . " <" . $from_mail . ">rn";
  189. $header .= "Reply-To: " . $replyto . "rn";
  190.  
  191. $header .= "MIME-Version: 1.0rn";
  192. $header .= "Content-Type: multipart/mixed; boundary="" . $uid . ""rnrn";
  193. $header .= "This is a multi-part message in MIME format.rn";
  194. $header .= "--" . $uid . "rn";
  195.  
  196. // You add html "Content-type: text/html; charset=utf-8n" or for Text "Content-type:text/plain; charset=iso-8859-1rn" by I.khan
  197. $header .= "Content-type:text/html; charset=utf-8n";
  198. $header .= "Content-Transfer-Encoding: 7bitrnrn";
  199.  
  200. // User Message you can add HTML if You Selected HTML content
  201. $header .= "<div style='color: red'>" . $message . "</div>rnrn";
  202.  
  203. $header .= "--" . $uid . "rn";
  204. $header .= "Content-Type: application/octet-stream; name="" . $filename . ""rn"; // use different content types here
  205. $header .= "Content-Transfer-Encoding: base64rn";
  206. $header .= "Content-Disposition: attachment; filename="" . $filename . ""rnrn"; // For Attachment
  207. $header .= $content . "rnrn";
  208. $header .= "--" . $uid . "--";
  209. if (mail($mailto, $subject, "", $header)) {
  210. echo "<script>alert('Success');</script>"; // or use booleans here
  211. } else {
  212. echo "<script>alert('Failed');</script>";
  213. }
  214. }
  215.  
  216. <?php
  217.  
  218. if ($_POST && isset($_FILES['file'])) {
  219. $recipient_email = "recipient@yourmail.com"; //recepient
  220. $from_email = "info@your_domain.com"; //from email using site domain.
  221. $subject = "Attachment email from your website!"; //email subject line
  222.  
  223. $sender_name = filter_var($_POST["s_name"], FILTER_SANITIZE_STRING); //capture sender name
  224. $sender_email = filter_var($_POST["s_email"], FILTER_SANITIZE_STRING); //capture sender email
  225. $sender_message = filter_var($_POST["s_message"], FILTER_SANITIZE_STRING); //capture message
  226. $attachments = $_FILES['file'];
  227.  
  228. //php validation
  229. if (strlen($sender_name) < 4) {
  230. die('Name is too short or empty');
  231. }
  232. if (!filter_var($sender_email, FILTER_VALIDATE_EMAIL)) {
  233. die('Invalid email');
  234. }
  235. if (strlen($sender_message) < 4) {
  236. die('Too short message! Please enter something');
  237. }
  238.  
  239. $file_count = count($attachments['name']); //count total files attached
  240. $boundary = md5("specialToken$4332"); // boundary token to be used
  241.  
  242. if ($file_count > 0) { //if attachment exists
  243. //header
  244. $headers = "MIME-Version: 1.0rn";
  245. $headers .= "From:" . $from_email . "rn";
  246. $headers .= "Reply-To: " . $sender_email . "" . "rn";
  247. $headers .= "Content-Type: multipart/mixed; boundary = $boundaryrnrn";
  248.  
  249. //message text
  250. $body = "--$boundaryrn";
  251. $body .= "Content-Type: text/plain; charset=ISO-8859-1rn";
  252. $body .= "Content-Transfer-Encoding: base64rnrn";
  253. $body .= chunk_split(base64_encode($sender_message));
  254.  
  255. //attachments
  256. for ($x = 0; $x < $file_count; $x++) {
  257. if (!empty($attachments['name'][$x])) {
  258.  
  259. if ($attachments['error'][$x] > 0) { //exit script and output error if we encounter any
  260. $mymsg = array(
  261. 1 => "The uploaded file exceeds the upload_max_filesize directive in php.ini",
  262. 2 => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form",
  263. 3 => "The uploaded file was only partially uploaded",
  264. 4 => "No file was uploaded",
  265. 6 => "Missing a temporary folder");
  266. die($mymsg[$attachments['error'][$x]]);
  267. }
  268.  
  269. //get file info
  270. $file_name = $attachments['name'][$x];
  271. $file_size = $attachments['size'][$x];
  272. $file_type = $attachments['type'][$x];
  273.  
  274. //read file
  275. $handle = fopen($attachments['tmp_name'][$x], "r");
  276. $content = fread($handle, $file_size);
  277. fclose($handle);
  278. $encoded_content = chunk_split(base64_encode($content)); //split into smaller chunks (RFC 2045)
  279.  
  280. $body .= "--$boundaryrn";
  281. $body .= "Content-Type: $file_type; name=" . $file_name . "rn";
  282. $body .= "Content-Disposition: attachment; filename=" . $file_name . "rn";
  283. $body .= "Content-Transfer-Encoding: base64rn";
  284. $body .= "X-Attachment-Id: " . rand(1000, 99999) . "rnrn";
  285. $body .= $encoded_content;
  286. }
  287. }
  288. } else { //send plain email otherwise
  289. $headers = "From:" . $from_email . "rn" .
  290. "Reply-To: " . $sender_email . "n" .
  291. "X-Mailer: PHP/" . phpversion();
  292. $body = $sender_message;
  293. }
  294.  
  295. $sentMail = @mail($recipient_email, $subject, $body, $headers);
  296. if ($sentMail) { //output success or failure messages
  297. die('Thank you for your email');
  298. } else {
  299. die('Could not send mail! Please check your PHP mail configuration.');
  300. }
  301. }
  302. ?>
  303.  
  304. <?php
  305.  
  306. // just edit these
  307. $to = "email1@domain.com, email2@domain.com"; // addresses to email pdf to
  308. $from = "sent_from@domain.com"; // address message is sent from
  309. $subject = "Your PDF email subject"; // email subject
  310. $body = "<p>The PDF is attached.</p>"; // email body
  311. $pdfLocation = "./your-pdf.pdf"; // file location
  312. $pdfName = "pdf-file.pdf"; // pdf file name recipient will get
  313. $filetype = "application/pdf"; // type
  314.  
  315. // creates headers and mime boundary
  316. $eol = PHP_EOL;
  317. $semi_rand = md5(time());
  318. $mime_boundary = "==Multipart_Boundary_$semi_rand";
  319. $headers = "From: $from$eolMIME-Version: 1.0$eol" .
  320. "Content-Type: multipart/mixed;$eol boundary="$mime_boundary"";
  321.  
  322. // add html message body
  323. $message = "--$mime_boundary$eol" .
  324. "Content-Type: text/html; charset="iso-8859-1"$eol" .
  325. "Content-Transfer-Encoding: 7bit$eol$eol$body$eol";
  326.  
  327. // fetches pdf
  328. $file = fopen($pdfLocation, 'rb');
  329. $data = fread($file, filesize($pdfLocation));
  330. fclose($file);
  331. $pdf = chunk_split(base64_encode($data));
  332.  
  333. // attaches pdf to email
  334. $message .= "--$mime_boundary$eol" .
  335. "Content-Type: $filetype;$eol name="$pdfName"$eol" .
  336. "Content-Disposition: attachment;$eol filename="$pdfName"$eol" .
  337. "Content-Transfer-Encoding: base64$eol$eol$pdf$eol--$mime_boundary--";
  338.  
  339. // Sends the email
  340. if(mail($to, $subject, $message, $headers)) {
  341. echo "The email was sent.";
  342. }
  343. else {
  344. echo "There was an error sending the mail.";
  345. }
  346.  
  347. <?php
  348. # $args must be an associative array
  349. # required keys: from, to, body
  350. # body can be a string or a [tree of] associative arrays. See examples below
  351. # optional keys: subject, reply_to, cc, bcc
  352. # EXAMPLES:
  353. # # text-only email:
  354. # email2(array(
  355. # 'from' => 'noreply@foo.com',
  356. # 'to' => 'jason@jasonwoof.com',
  357. # 'subject' => 'test',
  358. # # body will be text/plain because we're passing a string that doesn't start with '<'
  359. # 'body' => 'Hi, testing 1 2 3',
  360. # ));
  361. #
  362. # # html-only email
  363. # email2(array(
  364. # 'from' => 'noreply@foo.com',
  365. # 'to' => 'jason@jasonwoof.com',
  366. # 'subject' => 'test',
  367. # # body will be text/html because we're passing a string that starts with '<'
  368. # 'body' => '<h1>Hi!</h1>I like <a href="http://cheese.com">cheese</a>',
  369. # ));
  370. #
  371. # # text-only email (explicitly, in case first character is dynamic or something)
  372. # email2(array(
  373. # 'from' => 'noreply@foo.com',
  374. # 'to' => 'jason@jasonwoof.com',
  375. # 'subject' => 'test',
  376. # # body will be text/plain because we're passing a string that doesn't start with '<'
  377. # 'body' => array(
  378. # 'type' => 'text',
  379. # 'body' => $message_text,
  380. # )
  381. # ));
  382. #
  383. # # email with text and html alternatives (auto-detected mime types)
  384. # email2(array(
  385. # 'from' => 'noreply@foo.com',
  386. # 'to' => 'jason@jasonwoof.com',
  387. # 'subject' => 'test',
  388. # 'body' => array(
  389. # 'type' => 'alternatives',
  390. # 'body' => array(
  391. # "Hi!nnI like cheese",
  392. # '<h1>Hi!</h1><p>I like <a href="http://cheese.com">cheese</a></p>',
  393. # )
  394. # )
  395. # ));
  396. #
  397. # # email with text and html alternatives (explicit types)
  398. # email2(array(
  399. # 'from' => 'noreply@foo.com',
  400. # 'to' => 'jason@jasonwoof.com',
  401. # 'subject' => 'test',
  402. # 'body' => array(
  403. # 'type' => 'alternatives',
  404. # 'body' => array(
  405. # array(
  406. # 'type' => 'text',
  407. # 'body' => "Hi!nnI like cheese",
  408. # ),
  409. # array(
  410. # 'type' => 'html',
  411. # 'body' => '<h1>Hi!</h1><p>I like cheese</p>',
  412. # ),
  413. # )
  414. # )
  415. # ));
  416. #
  417. # # email with an attachment
  418. # email2(array(
  419. # 'from' => 'noreply@foo.com',
  420. # 'to' => 'jason@jasonwoof.com',
  421. # 'subject' => 'test',
  422. # 'body' => array(
  423. # 'type' => 'mixed',
  424. # 'body' => array(
  425. # "Hi!nnCheck out this (inline) image",
  426. # array(
  427. # 'type' => 'image/png',
  428. # 'disposition' => 'inline',
  429. # 'body' => $image_data, # raw file contents
  430. # ),
  431. # "Hi!nnAnd here's an attachment",
  432. # array(
  433. # 'type' => 'application/pdf; name="attachment.pdf"',
  434. # 'disposition' => 'attachment; filename="attachment.pdf"',
  435. # 'body' => $pdf_data, # raw file contents
  436. # ),
  437. # "Or you can use shorthand:",
  438. # array(
  439. # 'type' => 'application/pdf',
  440. # 'attachment' => 'attachment.pdf', # name for client (not data source)
  441. # 'body' => $pdf_data, # raw file contents
  442. # ),
  443. # )
  444. # )
  445. # ))
  446. function email2($args) {
  447. if (!isset($args['from'])) { return 1; }
  448. $from = $args['from'];
  449. if (!isset($args['to'])) { return 2; }
  450. $to = $args['to'];
  451. $subject = isset($args['subject']) ? $args['subject'] : '';
  452. $reply_to = isset($args['reply_to']) ? $args['reply_to'] : '';
  453. $cc = isset($args['cc']) ? $args['cc'] : '';
  454. $bcc = isset($args['bcc']) ? $args['bcc'] : '';
  455.  
  456. #FIXME should allow many more characters here (and do Q encoding)
  457. $subject = isset($args['subject']) ? $args['subject'] : '';
  458. $subject = preg_replace("|[^a-z0-9 _/#'.:&,-]|i", '_', $subject);
  459.  
  460. $headers = "From: $from";
  461. if($reply_to) {
  462. $headers .= PHP_EOL . "Reply-To: $reply_to";
  463. }
  464. if($cc) {
  465. $headers .= PHP_EOL . "CC: $cc";
  466. }
  467. if($bcc) {
  468. $headers .= PHP_EOL . "BCC: $bcc";
  469. }
  470.  
  471. $r = email2_helper($args['body']);
  472. $headers .= PHP_EOL . $r[0];
  473. $body = $r[1];
  474.  
  475. if (mail($to, $subject, $body, $headers)) {
  476. return 0;
  477. } else {
  478. return 5;
  479. }
  480. }
  481.  
  482. function email2_helper($body, $top = true) {
  483. if (is_string($body)) {
  484. if (substr($body, 0, 1) == '<') {
  485. return email2_helper(array('type' => 'html', 'body' => $body), $top);
  486. } else {
  487. return email2_helper(array('type' => 'text', 'body' => $body), $top);
  488. }
  489. }
  490. # now we can assume $body is an associative array
  491. # defaults:
  492. $type = 'application/octet-stream';
  493. $mime = false;
  494. $boundary = null;
  495. $disposition = null;
  496. $charset = false;
  497. # process 'type' first, because it sets defaults for others
  498. if (isset($body['type'])) {
  499. $type = $body['type'];
  500. if ($type === 'text') {
  501. $type = 'text/plain';
  502. $charset = true;
  503. } elseif ($type === 'html') {
  504. $type = 'text/html';
  505. $charset = true;
  506. } elseif ($type === 'alternative' || $type === 'alternatives') {
  507. $mime = true;
  508. $type = 'multipart/alternative';
  509. } elseif ($type === 'mixed') {
  510. $mime = true;
  511. $type = 'multipart/mixed';
  512. }
  513. }
  514. if (isset($body['disposition'])) {
  515. $disposition = $body['disposition'];
  516. }
  517. if (isset($body['attachment'])) {
  518. if ($disposition == null) {
  519. $disposition = 'attachment';
  520. }
  521. $disposition .= "; filename="{$body['attachment']}"";
  522. $type .= "; name="{$body['attachment']}"";
  523. }
  524. # make headers
  525. $headers = array();
  526. if ($top && $mime) {
  527. $headers[] = 'MIME-Version: 1.0';
  528. }
  529. if ($mime) {
  530. $boundary = md5('5sd^%Ca)~aAfF0=4mIN' . rand() . rand());
  531. $type .= "; boundary=$boundary";
  532. }
  533. if ($charset) {
  534. $type .= '; charset=' . (isset($body['charset']) ? $body['charset'] : 'UTF-8');
  535. }
  536. $headers[] = "Content-Type: $type";
  537. if ($disposition !== null) {
  538. $headers[] = "Content-Disposition: {$disposition}";
  539. }
  540.  
  541. $data = '';
  542. # return array, first el is headers, 2nd is body (php's mail() needs them separate)
  543. if ($mime) {
  544. foreach ($body['body'] as $sub_body) {
  545. $data .= "--$boundary" . PHP_EOL;
  546. $r = email2_helper($sub_body, false);
  547. $data .= $r[0] . PHP_EOL . PHP_EOL; # headers
  548. $data .= $r[1] . PHP_EOL . PHP_EOL; # body
  549. }
  550. $data .= "--$boundary--";
  551. } else {
  552. if(preg_match('/[^x09x0Ax0Dx20-x7E]/', $body['body'])) {
  553. $headers[] = "Content-Transfer-Encoding: base64";
  554. $data .= chunk_split(base64_encode($body['body']));
  555. } else {
  556. $data .= $body['body'];
  557. }
  558. }
  559. return array(join(PHP_EOL, $headers), $data);
  560. }
  561.  
  562. $to = "to@gmail.com";
  563. $subject = "Subject Of The Mail";
  564. $message = "Hi there,<br/><br/>This is my message.<br><br>";
  565.  
  566. $headers = "From: From-Name<from@gmail.com>";
  567. // boundary
  568. $semi_rand = md5(time());
  569. $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  570.  
  571. // headers for attachment
  572. $headers .= "nMIME-Version: 1.0n" . "Content-Type: multipart/mixed;n" . " boundary="{$mime_boundary}"";
  573.  
  574. // multipart boundary
  575. $message = "This is a multi-part message in MIME format.nn" . "--{$mime_boundary}n" . "Content-Type: text/html; charset=ISO-8859-1"n" . "Content-Transfer-Encoding: 7bitnn" . $message . "nn";
  576.  
  577. $message .= "--{$mime_boundary}n";
  578. $filepath = 'uploads/'.$_FILES['image']['name'];
  579. move_uploaded_file($_FILES['image']['tmp_name'], $filepath); //upload the file
  580. $filename = $_FILES['image']['name'];
  581. $file = fopen($filepath, "rb");
  582. $data = fread($file, filesize($filepath));
  583. fclose($file);
  584. $data = chunk_split(base64_encode($data));
  585. $message .= "Content-Type: {"application/octet-stream"};n" . " name="$filename"n" .
  586. "Content-Disposition: attachment;n" . " filename="$filename"n" .
  587. "Content-Transfer-Encoding: base64nn" . $data . "nn";
  588. $message .= "--{$mime_boundary}n";
  589.  
  590. mail($to, $subject, $message, $headers);
  591.  
  592. <?php
  593. function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
  594. $file = $path.$filename;
  595. $file_size = filesize($file);
  596. $handle = fopen($file, "r");
  597. $content = fread($handle, $file_size);
  598. fclose($handle);
  599. $content = chunk_split(base64_encode($content));
  600. $uid = md5(uniqid(time()));
  601. $header = "From: ".$from_name." <".$from_mail.">rn";
  602. $header .= "Reply-To: ".$replyto."rn";
  603. $header .= "MIME-Version: 1.0rn";
  604. $header .= "Content-Type: multipart/mixed; boundary="".$uid.""rnrn";
  605. $header .= "This is a multi-part message in MIME format.rn";
  606. $header .= "--".$uid."rn";
  607. $header .= "Content-type:text/plain; charset=iso-8859-1rn";
  608. $header .= "Content-Transfer-Encoding: 7bitrnrn";
  609. $header .= $message."rnrn";
  610. $header .= "--".$uid."rn";
  611. $header .= "Content-Type: application/octet-stream; name="".$filename.""rn"; // use different content types here
  612. $header .= "Content-Transfer-Encoding: base64rn";
  613. $header .= "Content-Disposition: attachment; filename="".$filename.""rnrn";
  614. $header .= $content."rnrn";
  615. $header .= "--".$uid."--";
  616. if (mail($mailto, $subject, "", $header)) {
  617. echo "mail send ... OK"; // or use booleans here
  618. } else {
  619. echo "mail send ... ERROR!";
  620. }
  621. }
  622.  
  623. //start editing and inputting attachment details here
  624. $my_file = "somefile.zip";
  625. $my_path = "/your_path/to_the_attachment/";
  626. $my_name = "Olaf Lederer";
  627. $my_mail = "my@mail.com";
  628. $my_replyto = "my_reply_to@mail.net";
  629. $my_subject = "This is a mail with attachment.";
  630. $my_message = "Hallo,rndo you like this script? I hope it will help.rnrngr. Olaf";
  631. mail_attachment($my_file, $my_path, "recipient@mail.org", $my_mail, $my_name, $my_replyto, $my_subject, $my_message);
  632. ?>
  633.  
  634. if (isset($_POST['submit'])) {
  635. extract($_POST);
  636. require_once('mail/class.phpmailer.php');
  637.  
  638. $subject = "$name Applied For - $position";
  639. $email_message = "<div>Thanks for Applying ....</div> ";
  640.  
  641. $mail = new PHPMailer;
  642. $mail->IsSMTP(); // telling the class to use SMTP
  643. $mail->Host = "mail.companyname.com"; // SMTP server
  644. $mail->SMTPDebug = 0;
  645. $mail->SMTPAuth = true;
  646. $mail->SMTPSecure = "ssl";
  647. $mail->Host = "smtp.gmail.com";
  648. $mail->Port = 465;
  649. $mail->IsHTML(true);
  650. $mail->Username = "info@companyname.com"; // GMAIL username
  651. $mail->Password = "mailPassword"; // GMAIL password
  652.  
  653. $mail->SetFrom('info@companyname.com', 'new application submitted');
  654. $mail->AddReplyTo("name@yourdomain.com","First Last");
  655. $mail->Subject = "your subject";
  656.  
  657. $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
  658.  
  659. $mail->MsgHTML($email_message);
  660.  
  661. $address = 'info@companyname.com';
  662. $mail->AddAddress($address, "companyname");
  663.  
  664. $mail->AddAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']); // attachment
  665.  
  666. if (!$mail->Send()) {
  667. /* Error */
  668. echo 'Message not Sent! Email at info@companyname.com';
  669. } else {
  670. /* Success */
  671. echo 'Sent Successfully! <b> Check your Mail</b>';
  672. }
  673. }
Add Comment
Please, Sign In to add comment