sasori Posted September 4, 2010 Share Posted September 4, 2010 it doesn't work, file cannot be read, I don't know why it can't, I've played with the $fileLocation for quite a while now, just to reach the "public" folder, please tell me your idea about it public function sendEmailWithAttachmentAction() { //create smtp connection $configInfo = array( 'auth' => 'login', 'ssl' => 'ssl', 'username' => '[email protected]', 'password' => 'mypassword', 'port' => '465' ); $smtpHost = new Zend_Mail_Transport_Smtp('smtp.gmail.com',$configInfo); //create zend mail object $MailObj = new Zend_Mail(); $message = "<h1>Welcome to the example</h1>". "<br><p>An example email with attachemen</p>"; $fileLocation = '/../../../public/files/1.jpg'; //check if the file exists and is readable if(!$fileHandler = fopen($fileLocation,'rb')) { throw new Exception("The file could not be found or is not readable"); } $fileContent = fread($fileHandler, $filesize($fileLocation)); fflush($fileHandler); fclose($fileHandler); //intialize parameters $fromEmail = "[email protected]"; $fromFullName = "dummyname dummysurname"; $to = "[email protected]"; $subject = "This is a sample attachment"; $MailObj->setBodyHtml($message); $MailObj->setFrom($fromEmail,$fromFullName); $MailObj->addTo($to); $MailObj->setSubject($subject); $MailObj->createAttachment($fileContent, 'image/jpeg', Zend_Mime::DISPOSITION_ATTACHMENT); try { $MailObj->send($smtpHost); echo "Email Attachement sent"; } catch(Zend_Mail_Exception $e) { echo $e->getMessage(); } $this->_helper->viewRenderer->setRenderNo(); } screen shot Link to comment https://forums.phpfreaks.com/topic/212484-zf-email-with-attachment-help/ Share on other sites More sharing options...
ignace Posted September 4, 2010 Share Posted September 4, 2010 Presuming you used zf.bat you should find a constant APPLICATION_PATH in the index.php which you can use throughout your project, like: $fileLocation = APPLICATION_PATH . '/files/1.jpg'; Link to comment https://forums.phpfreaks.com/topic/212484-zf-email-with-attachment-help/#findComment-1107130 Share on other sites More sharing options...
sasori Posted September 5, 2010 Author Share Posted September 5, 2010 I won't mark this as solved yet..imma skip this for now Link to comment https://forums.phpfreaks.com/topic/212484-zf-email-with-attachment-help/#findComment-1107398 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.