Jump to content

ZF email with attachment help


sasori

Recommended Posts

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' => '[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

29lfspe.jpg

 

Link to comment
https://forums.phpfreaks.com/topic/212484-zf-email-with-attachment-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.