Jump to content

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

29lfspe.jpg

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.