Solved

add email attachment in smarty template and phpmailer

Posted on 2013-05-23
1
933 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 7

Accepted Solution

by:
Robert Saylor earned 500 total points
ID: 39190959
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

615 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