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' => 'myemail@gmail.com', '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 = "dummysender@gmali.com"; $fromFullName = "dummyname dummysurname"; $to = "recipient@gmail.com"; $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 Quote 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'; Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.