Author Topic: ZF email with attachment help  (Read 641 times)

0 Members and 1 Guest are viewing this topic.

Offline sasoriTopic starter

  • Enthusiast
  • Posts: 269
    • View Profile
ZF email with attachment help
« on: September 03, 2010, 09:52:58 PM »
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  :confused:


	
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


Offline ignace

  • Guru
  • Freak!
  • *
  • Posts: 5,093
  • Gender: Male
    • View Profile
Re: ZF email with attachment help
« Reply #1 on: September 04, 2010, 04:36:13 AM »
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';
Developer from Belgium, Vlaams-Brabant

Offline sasoriTopic starter

  • Enthusiast
  • Posts: 269
    • View Profile
Re: ZF email with attachment help
« Reply #2 on: September 05, 2010, 02:47:18 AM »
I won't mark this as solved yet..imma skip this for now