Post by lev » Mon Jun 30, 2008 11:08 pm

Gilpat and the other guys... 

MY FAULT!
I must have been retarded at the time but I did not include the template file in the original zip.. terribly sorry....

Im in a rush so the location for the setting.tpl file is a full path, but it must go under your store's /admin/template/default/content/

Soory again and let me know if this solves your issues

lev
New member

Posts

Joined
Wed Apr 30, 2008 10:47 pm

Post by Casperitus » Tue Nov 04, 2008 12:45 pm

Okey this is really important...

The basic MailSend of OpenCart Wasn't working [ Excpet for internal server mails ( mails @mydomain ) ] but if tried to use someone else mail like @hotmail or somthing he don't recive anything...

My SMTP Server requiers logon, so i think i need to add SMTP Password to your modification . how can i do that ?! becuase i still not reciving mails after appliening your mod

Newbie

Posts

Joined
Mon May 05, 2008 8:53 pm

Post by ptal » Wed Nov 05, 2008 8:46 pm

I'd also like to know how to use SMTP. I've downloaded the Swift Mailer that has been mentioned before but have no idea how this might interface within mail.php
Any ideas?

Newbie

Posts

Joined
Wed May 28, 2008 2:48 pm

Post by lev » Thu Nov 06, 2008 8:12 am

have you two tried the solution explained above?

lev
New member

Posts

Joined
Wed Apr 30, 2008 10:47 pm

Post by hm2k » Thu Nov 06, 2008 8:51 am

You'll probably find that for some reason or another PHP's mail() function isn't suitable for their setup/operating system.

Alternatives include:
http://pear.php.net/package/Mail
http://sourceforge.net/projects/phpmailer

There is also swiftmailer, which i've only just heard of.

In past projects phpmailer was the most suitable option, I suspect we may incorporate this into OpenCart v0.8.

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by bruce » Thu Nov 06, 2008 9:44 am

This will give you most of what you need to do to integrate swift mailer. It uses an smtp server and this example also shows how to convert images in the html email template to embedded images in the html email.

The project I did this for was based on 0.7.7.

create a folder library\external\Swift and upload the swift mailer to that location. The result is shown in the attached image.

modify config.php (admin as well) by adding something similar to the following

Code: Select all


define('HOSTING_DIR',         'C:/xampp/htdocs/077');

define('DIR_EXTERNAL',   HOSTING_DIR . '/library/external/');


if ( ! defined( 'PATH_SEPARATOR' ) )
{
    if ( strpos( $_ENV[ 'OS' ], 'Win' ) !== false )
        define( 'PATH_SEPARATOR', ';' );
    else
        define( 'PATH_SEPARATOR', ':' );
}



modify index.php (in admin as well)

Code: Select all

// External packages
$include_path = ini_get('include_path') ;
$include_path .= PATH_SEPARATOR . DIR_EXTERNAL;
$include_path .= PATH_SEPARATOR . DIR_EXTERNAL . '/Swift/';  // Swift Mailer
ini_set('include_path', $include_path);
backup library\mail.php and replace it with

Code: Select all

<?php
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
// example of how to modify HTML contents
require_once 'simple_html_dom.php';

class Mail
{
	var $to;
	var $cc;
	var $bcc;
	var $from;
	var $sender;
	var $subject;
	var $charset;
	var $text;
	var $html;
	var $attachments = array();

	function setTo($to)
	{
		$this->to = $to;
	}

	function setCc($cc)
	{
		$this->cc = $cc;
	}

	function setBcc($bcc)
	{
		$this->bcc = $bcc;
	}

	function setFrom($from)
	{
		$this->from = $from;
	}

	function setSender($sender)
	{
		$this->sender = $sender;
	}

	function setSubject($subject)
	{
		$this->subject = $subject;
	}

	function setCharacterSet($charset)
	{
		$this->charset = $charset;
	}

	function setText($text)
	{
		$this->text = $text;
	}

	function setHtml($html)
	{
		$this->html = $html;
	}

	function setAttachment($attachment)
	{
		$this->attachments[] = $attachment;
	}

	//
	//  Modified send to fail without killing the web site with an exit.
	//  ToDo: When logging is implemented, log these errors so the store owner can respond appropriately.
	//
	function send(&$errMessage)
	{
		if (!$this->to)
		{
			$errMessage .= 'mail->send: To not set ';
			return false;
		}

		if (!$this->from)
		{
			$errMessage .= 'mail->send:From not set ';
			return false;
		}

/*		if (!$this->sender)
		{
			return false;
			//exit('Error: Sender not set');
		}

*/
		if (!$this->subject)
		{
			//$this->subject = '(no subject)';
			$errMessage .= 'mail->send: Subject not set ';
			return false;
			//exit('Error: Subject not set');
		}

		if ((!$this->text) && (!$this->html))
		{
			$errMessage .= 'mail->send: message has no body ';
			return false;
			//exit('Error: Message not set');
		}

		$recipients = new Swift_RecipientList();

		if (is_array($this->to))
		{
			foreach($this->to as $to)
			{
				$recipients->addTo($to);
			}
		}
		else
		{
			$recipients->addTo($this->to);
		}

		if ($this->cc)
		{
			if (is_array($this->cc))
			{
				foreach($this->cc as $cc)
				{
					$recipients->addCc($cc);
				}
			}
			else
			{
				$recipients->addCc($this->cc);
			}
		}

		if ($this->bcc)
		{
			if (is_array($this->bcc))
			{
				foreach($this->bcc as $bcc)
				{
					$recipients->addBcc($bcc);
				}
			}
			else
			{
				$recipients->addBcc($this->bcc);
			}
		}

		if ($this->charset)
		{
			$charset = $this->charset;
		}
		else
		{
			$charset = 'utf-8';
		}
		try
		{
				$smtp = new Swift_Connection_SMTP("your smtp server name", 25);
				$swift = new Swift($smtp);
				$message = new Swift_Message($this->subject);

				if ($this->html)
				{
					//
					//  Parse out all the image links and embed them.
					//
					//  Hack: The swiftmailer has a plugin for this but I could not make it work quickly
					//        and have not the time to investigate. Also we do not check to see if the image
					//        is already embedded. It just gets embedded again.
					//
					try
					{
						$dom = new simple_html_dom();
						$dom->load($this->html);

						foreach($dom->find('img') as $node)
						{
							$img = new Swift_Message_Image(new Swift_File($node->src));
							$src = $message->attach($img);
							$node->src = $src;
						}
					}
					catch(Exception $ex)
					{
						$errMessage .= "There was a problem converting the images: " . $ex->getMessage() . ' ';
						return false;
					}

					// ToDo: later do the same for all style sheets
					//       For the moment, style sheet links must be edited from the html and embedded in the template as styles.

					$message->attach(new Swift_Message_Part($dom->outertext, "text/html"));
				}

				if ($this->text)
				{
					$message->attach(new Swift_Message_Part($this->text));
				}

				//
				// ToDo:  Handle attachments when and if required by accolades.
				//
				$send_count = $swift->send($message, $recipients, $this->from);

				//recommended to do this
				$swift->disconnect();

				return $send_count;
		}
		catch (Swift_ConnectionException $e)
		{
			$errMessage .= "There was a problem communicating with SMTP: " . $e->getMessage() . ' ';
			return false;
		}
		catch (Swift_Message_MimeException $e)
		{
			$errMessage .= "There was an unexpected problem building the email:" . $e->getMessage() . ' ';
			return false;
		}
	}
}
?>
finally, download simple_html_dom from http://sourceforge.net/projects/simplehtmldom and place simple_html_dom.php in the library\external folder.

usage example:

Code: Select all

				$msg = $this->locator->create('template');
				//  add data to the email template.
				$msg->set('recipient_fullname', $rec_address['firstname'] . ' ' . $rec_address['lastname']);


				//
				//  Confirmation email to recipient with blind copy to store email address
				//
				$email->setSubject('Confirmation');
				$email->setTo($rec_address['email']);
				$email->setFrom($config->get('config_email'));
				$email->setBcc($config->get('config_email'));
				$email->setHtml($msg->fetch('content/email_accepted_recipient.tpl'));
				if (!$email->send($errMessage))
				{
					// handle the error 'Failed to send recipient acceptance confirmation email. '
				}

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by ptal » Mon Nov 10, 2008 7:38 pm

hm2k wrote: I suspect we may incorporate this into OpenCart v0.8.
Do you think that this sort of thing might make its way to a module? I'm a true novice at this php stuff.

Newbie

Posts

Joined
Wed May 28, 2008 2:48 pm

Post by bruce » Mon Nov 10, 2008 7:50 pm

As you can see from the scope of the changes I suggested, they are not really modular in nature. It is an integration that is required. If you must have this, send me a PM and I will help you.

Cheers

Bruce

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by Qphoria » Mon Nov 10, 2008 8:09 pm

FYI. This has been added to the todo list for v0.8

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by hm2k » Mon Jan 19, 2009 7:50 pm

A ready to work solution can be found here:

http://forum.opencart.com/index.php/top ... l#msg13537

I am thinking about adding this into 0.7.9...?

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by Qphoria » Mon Jan 19, 2009 10:27 pm

I'd say if you are going to add this, you should add some radios on the Admin->configuration->setting->Mail tab

"Send Copy of Account Create Email to Store owner: Yes/No"
"Send Copy of Order Email to Store owner: Yes/No"

I would like the order email forwarded for sure, but not the account create email.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by hm2k » Tue Jan 20, 2009 1:33 am

I was just thinking that it could be added, and people could remove it if they didn't want it, for now.

After all, I think most people would want it by default, those that don't could hack it out.

Depends whether we want it to be opt-in or opt-out by default?

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by Qphoria » Tue Jan 20, 2009 4:19 am

i'd rather leave it as opt-in then if we are not going to offer configuration options. We can save it for 0.8 when it can be properly done.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by hm2k » Fri Feb 06, 2009 4:28 am

Last edited by Qphoria on Fri Feb 06, 2009 5:40 am, edited 1 time in total.

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK
Who is online

Users browsing this forum: No registered users and 8 guests