How to add an attachment in email in magento?
I want to add a custom email script to add an attachment in controller file
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Aviance School is one of the largest web solutions platform in India for developers to learn and share their programming knowledge and build their careers.
<?php
$ToName=”Sender Name”;
/* Sender Email */
$ToEmail=”domainname.com”;
$mail = new Zend_Mail();
$mail->setType(Zend_Mime::MULTIPART_RELATED);
$mail->setFrom(‘support@example.com’, ‘Your business name goes here’);
$mail->addTo($ToEmail, $ToName);
$sub=”Email subject goes here”;
$mail->setSubject($sub);
$dir = Mage::getBaseUrl();
if (isset($_FILES[‘filename’][‘name’]) && $_FILES[‘filename’][‘name’] != ”) {
$uploaddir22=”media/uploads/”;
$f_name=time() .”_”.$_FILES[‘filename’][‘name’];
$uploadfile22 = $uploaddir22 . $f_name;
if(move_uploaded_file($_FILES[‘filename’][‘tmp_name’], $uploadfile22)) {
$filename = $f_name;
chmod($uploadfile22, 0777);
}
$ext1 = pathinfo($filename, PATHINFO_EXTENSION);
$exttype1=’application/’.$ext1;
$file = $mail->createAttachment(file_get_contents($uploadfile22));
$file ->type = $exttype1;
$file ->disposition = Zend_Mime::DISPOSITION_INLINE;
$file ->encoding = Zend_Mime::ENCODING_BASE64;
$file ->filename = $filename;
}
$html = “<h1>Body of your email data goes here</h1>”;
$mail->setBodyHtml($html);
try{
if (! $mail->send()) {
throw new Exception ();
}else{
echo “Email sent successfully”;
}
}
catch(Exception $ex){
echo $ex->getMessage();
}
?>