Solved

add email attachment in smarty template and phpmailer

Posted on 2013-05-23
1
855 Views
Last Modified: 2013-06-08
my site have a email script which have few file to perform a simple contact form submit, i suft the net but no clue on now to make it send theattachment, my eye was blur, experts please help.

2 html + 1 php file script as below

one is html file to display the form

<form name="contactusForm" enctype="multipart/form-data" action="{$url_https}p=contact_us" method="post" onsubmit="return CheckContactusForm(this)">            
....
<div class="field clearfix">
                        <label>Upload</label>
                        <input name="form[upload]" type="file" id="upload" />
</div>
...

one is php file to perform the sending script

function emailSupport($contact){
      global $settings;

      view()->assign("fname", $contact["fname"]);
      view()->assign("subject", $contact["subject"]);
      view()->assign("message", $contact["message"]);
        view()->assign("email"=>$contactus["email"], "name" => $contact["fname"]);
      send_mail("name@somename.com","Customer Inquiry",$message,$from, "html");
}
0
Comment
Question by:john80988
1 Comment
 
LVL 6

Accepted Solution

by:
Robert Saylor earned 500 total points
Comment Utility
This is what we use for sending attachments:

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-type: text/html; 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!";
    }
}

Open in new window


You can process the upload to the server or use a file_get_contents then pass that to the function mail_attachments

mail_attachment($my_file, $my_path, $to_email, $my_mail, $my_name, $my_replyto, $my_subject, $my_message);

Open in new window

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now