0
                $name           = $post["name"];
                $email          = $post["email"];
                $address_line_1 = $post["address"]; 
                $attachment     = $post["attachment"]; 
                $body           = "";

                $to      = "abc@gmail.com";
                $subject = "Career Inquiry";
                $body   .= "<p>New Career Inquiry.</p>";
                $body   .= "<p>Name : " . $name . "<p>";
                $body   .= "<p>Email  : " . $email . "<p>";
                $body   .= "<p>Address Line 1 : " . $address_line_1 . "<p>";
                //$body   .= "<p>Address Line 2 : " . $address_line_2 .   "<p>";
                //$body   .= "<p>Address Line 3 : " . $address_line_3 . "<p>";
                //$body   .= "<p>City : " . $city . "<p>";
                //$body   .= "<p>Post Code : " . $postcode . "<p>";
                //$body   .= "<p>Country : " . $country . "<p>";

                $body .= "<p>Kind regards,</p><p>example Admin</p>";

                $from = $email;

                $mail = Mage::getModel('core/email');
                $mail->setToName('Pranav');
                $mail->setToEmail($to);
                $mail->setBody($body);
                $mail->setSubject($subject);
                $mail->setFromEmail($from);
                $mail->setFromName($name); //Set from name
                $mail->setType('html');// YOu can use Html or text as Mail format
                //$mail->setBodyHTML($body);  // your content or message

                //add attachment start                
                $base_path = Mage::getBaseDir('base');
                $uploadfile = $base_path."\media\\resume\\" . basename($_FILES['attachment']['name']);
                $filename =$_FILES['attachment']['name'];
                move_uploaded_file($_FILES['attachment']['tmp_name'], $uploadfile);
                $mail->addAttachment($uploadfile, $filename);
                //add attachment end                

                $mail->send();

                Mage::getSingleton('core/session')->addSuccess('Your inquiry     was submitted and will be responded to as soon as possible. Thank you for     contacting us.');
                $this->_redirect('*/*/');
                return;
0

Add Attachment :-

$mailTemplate->getMail()->createAttachment(
          file_get_contents(Mage::getBaseDir('base') . '/media/file/file.pdf'), //location of file
          Zend_Mime::TYPE_OCTETSTREAM,
          Zend_Mime::DISPOSITION_ATTACHMENT,
          Zend_Mime::ENCODING_BASE64,
          'file.pdf'
  );
  $mailTemplate->send('toemail@email.com','subject','set message');
0

You can use this code in phtml or controller to send mail with attached file

$mailTemplate = Mage::getModel('core/email_template');
$mailTemplate->setSenderName('Sender Name'); 
$mailTemplate->setSenderEmail('sender@sender.email');
$mailTemplate->setTemplateSubject('Subject Title');
$mailTemplate->setTemplateText('Body Text');
// add attachment
$mailTemplate->getMail()->createAttachment(
        file_get_contents(Mage::getBaseDir('base') . '/media/file/file.pdf'), //location of file
        Zend_Mime::TYPE_OCTETSTREAM,
        Zend_Mime::DISPOSITION_ATTACHMENT,
        Zend_Mime::ENCODING_BASE64,
        'file.pdf'
);
$mailTemplate->send('toemail@email.com','subject','set message');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.