How to send attachment by swift in php?

Attach and send(mail) files through SMTP using PHP Mailer class?

  • hi evryone!!! I m usinh PHP mailer class to send email. It works fine if i send only text mail or text with image. But when i try to send mail with attachment it causes error like "Function set_magic_quotes_runtime() depreciated" . What 's the meaning and what is solution of this problem? Is it possible to attach and send files through php mailer class? My code for attachment is AddAttachment("abc.pdf","abc"). the file abc is in the same folder where my scripting file lives. So i have not specify full path for file. I hope i will get correct solution

  • Answer:

    <?php function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) { $file = $path.$filename; $file_size = filesize($file); $handle = fopen($file, "r"); $content = fread($handle, $file_size); fclose($handle); $content = chunk_split(base64_encode($content)); $uid = md5(uniqid(time())); $name = basename($file); $header = "From: ".$from_name." <".$from_mail.">\r\n"; $header .= "Reply-To: ".$replyto."\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message."\r\n\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; $header .= $content."\r\n\r\n"; $header .= "--".$uid."--"; if (mail($mailto, $subject, "", $header)) { echo "mail send ... OK"; // or use booleans here } else { echo "mail send ... ERROR!"; } } ?> $my_file = "somefile.zip"; $my_path = $_SERVER['DOCUMENT_ROOT']."/your_path_he... $my_name = "Olaf Lederer"; $my_mail = "[email protected]"; $my_replyto = "[email protected]"; $my_subject = "This is a mail with attachment."; $my_message = "Hallo,\r\ndo you like this script? I hope it will help.\r\n\r\ngr. Olaf"; mail_attachment($my_file, $my_path, "[email protected]", $my_mail, $my_name, $my_replyto, $my_subject, $my_message); ?> easy sweet and simple. post your code online can help you debug. "Function set_magic_quotes_runtime() depreciated" check http://www.php.net/manual/en/function.get-magic-quotes-runtime.php

Tushar at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

<?php function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) { $file = $path.$filename; $file_size = filesize($file); $handle = fopen($file, "r"); $content = fread($handle, $file_size); fclose($handle); $content = chunk_split(base64_encode($content)); $uid = md5(uniqid(time())); $name = basename($file); $header = "From: ".$from_name." <".$from_mail.">\r\n"; $header .= "Reply-To: ".$replyto."\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message."\r\n\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; $header .= $content."\r\n\r\n"; $header .= "--".$uid."--"; if (mail($mailto, $subject, "", $header)) { echo "mail send ... OK"; // or use booleans here } else { echo "mail send ... ERROR!"; } } ?> $my_file = "somefile.zip"; $my_path = $_SERVER['DOCUMENT_ROOT']."/your_path_he… $my_name = "Olaf Lederer"; $my_mail = "[email protected]"; $my_replyto = "[email protected]"; $my_subject = "This is a mail with attachment."; $my_message = "Hallo,\r\ndo you like this script? I hope it will help.\r\n\r\ngr. Olaf"; mail_attachment($my_file, $my_path, "[email protected]", $my_mail, $my_name, $my_replyto, $my_subject, $my_message); ?> easy sweet and simple. post your code online can help you debug. "Function set_magic_quotes_runtime() depreciated" check http://www.php.net/manual/en/function.get-magic-quotes-runtime.php

LoRD ARaSSeN

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.