Post by ptal78 » Sun Jul 05, 2009 6:57 pm

I really feel like a newbie to all this.

Does anyone have suggestions or links for setting up sendmail through webmin to work with opencart?
I figure this could be a good starting place for people like me that jump in the deep end without floaties.

The following topics could be discussed;

Sendmail - Sendmail Options, Network Ports, Trusted Users, Outgoing Domains (Just guessing here)
PHP mail()
Firewall requirements
MX records (only if required for outgoing Opencart email)

It seems impossible to find a simple guide to set this up. Any good help is much appreciated :)

Not looking for help on total Mail Servers - Just what is required for opencart server side outgoing mail.

Thanx peoples

Newbie

Posts

Joined
Sat Jul 04, 2009 9:05 pm

Post by ssk » Fri Jul 17, 2009 6:35 am

I am in the exact same boat. I too feel like a noob at this. I've been scouring the web, this forum, and my hosts help pages to try and figure out where to go, and what to do to make the email function work.

I've learned that php doesn't need a seperate mail server
That some hosts block php.mail (mine does not)
I know the relay server name to use if OpenCart is using something besides the mail() function (but apparently that IS what it is using.)

I get this error message when I try to send email:

Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay for (my entered email address) D:\Hosting\......\html\system\library\mail.php on line 124

Warning: Cannot modify header information - headers already sent by (output started at D:\Hosting\......\html\system\library\mail.php:124) in D:\Hosting\.....\html\system\engine\controller.php on line 23

Where do I go, what do I do? I want to learn, I want to resolve this. I will be very grateful.

Do people install OpenCart and have the mail function work with no tweaking or changing of settings?

ssk
Newbie

Posts

Joined
Fri Jul 17, 2009 6:16 am

Post by Daniel » Sat Jul 18, 2009 2:23 am

I will look into how to send mails using pop3 anbd it to a future version. If its just easy to do i might be able to add it in the next version.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by Daniel » Sat Jul 18, 2009 2:40 am

also i would just like to say that most of the hosts with the mail function disabled are free hosts becuase they don;t want there servers used to send spam.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by Daniel » Sat Jul 18, 2009 4:18 am

ok i got it working quite quickly. Just replace the the mail class with this;

Code: Select all

<?php 
final class Mail {
	protected $protocol = 'mail';	
	protected $smtp_host = '';
	protected $smtp_username = '';
	protected $smtp_password = '';
	protected $smtp_port = '25';
	protected $smtp_timeout	= 5;
	protected $to;
  	protected $from;
  	protected $sender;
  	protected $subject;
  	protected $text;
  	protected $html;
  	protected $attachments = array();

	public function __construct($protocol = 'mail', $smtp_host = '', $smtp_username = '', $smtp_password = '', $smtp_port = '25', $smtp_timeout = '5') {
		$this->protocol = $protocol;
		$this->smtp_host = $smtp_host;
		$this->smtp_username = $smtp_username;
		$this->smtp_password = $smtp_password;
		$this->smtp_port = $smtp_port;
		$this->smtp_timeout = $smtp_timeout;
	}
	
	public function setTo($to) {
    	$this->to = $to;
  	}
 
  	public function setFrom($from) {
    	$this->from = $from;
  	}
 
  	public function setSender($sender) {
    	$this->sender = $sender;
  	}
 
  	public function setSubject($subject) {
    	$this->subject = $subject;
  	}

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

  	public function setHtml($html) {
    	$this->html = $html;
  	}
	
  	public function addAttachment($attachments) {
    	$this->attachments[] = $attachments;
  	}

  	public function send() {	
    	if (!$this->to) {
      		exit('Error: E-Mail to required!');
    	}
	
    	if (!$this->from) {
      		exit('Error: E-Mail from required!');
    	}
    
    	if (!$this->sender) {
      		exit('Error: E-Mail sender required!');
    	}
		
		if (!$this->subject) {
      		exit('Error: E-Mail subject required!');
    	}
			
		if ((!$this->text) && (!$this->html)) {
      		exit('Error: E-Mail message required!');
    	}

		if (is_array($this->to)) {
      		$to = implode($this->to, ',');
    	} else {
      		$to = $this->to;
    	}
	  	
		$boundary = '----=_NextPart_' . md5(rand());  
	    
		if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) { 
      		$eol = "\r\n"; 
    	} elseif (strtoupper(substr(PHP_OS, 0, 3)=='MAC')) { 
      		$eol = "\r"; 
    	} else { 
      		$eol = "\n"; 
    	} 	
		
		$headers  = 'From: ' . $this->sender . '<' . $this->from . '>' . $eol; 
    	$headers .= 'Reply-To: ' . $this->sender . '<' . $this->from . '>' . $eol;   
    	$headers .= 'X-Mailer: PHP/' . phpversion() . $eol;  
    	$headers .= 'MIME-Version: 1.0' . $eol; 
    	$headers .= 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' . $eol;  
	
		if (!$this->html) {
	  		$message  = '--' . $boundary . $eol;  
	  		$message .= 'Content-Type: text/plain; charset="utf-8"' . $eol; 
	  		$message .= 'Content-Transfer-Encoding: base64' . $eol . $eol;
      		$message .= chunk_split(base64_encode($this->text));
		} else {
	  		$message  = '--' . $boundary . $eol;
	  		$message .= 'Content-Type: multipart/alternative; boundary="' . $boundary . '_alt"' . $eol . $eol;
	  		$message .= '--' . $boundary . '_alt' . $eol;
	  		$message .= 'Content-Type: text/plain; charset="utf-8"' . $eol; 
	  		$message .= 'Content-Transfer-Encoding: base64' . $eol;
	  
	  		if ($this->text) {
        		$message .= chunk_split(base64_encode($this->text));
	  		} else {
	    		$message .= chunk_split(base64_encode('This is a HTML email and your email client software does not support HTML email!'));
      		}	
	  
	  		$message .= '--' . $boundary . '_alt' . $eol;
      		$message .= 'Content-Type: text/html; charset="utf-8"' . $eol; 
      		$message .= 'Content-Transfer-Encoding: base64' . $eol . $eol;
	  		$message .= chunk_split(base64_encode($this->html)); 
			$message .= '--' . $boundary . '_alt--' . $eol;		 
		}
		
    	foreach ($this->attachments as $attachment) {  
      		$filename = basename($attachment);  
      		$handle = fopen($attachment, 'r'); 
      		$content = fread($handle, filesize($attachment));
      
	  		fclose($handle);  
	  
      		$message .= '--' . $boundary . $eol;
      		$message .= 'Content-Type: application/octetstream' . $eol;    
      		$message .= 'Content-Transfer-Encoding: base64' . $eol; 
      		$message .= 'Content-Disposition: attachment; filename="' . $filename . '"' . $eol; 
      		$message .= 'Content-ID: <' . $filename . '>' . $eol . $eol;
      		$message .= chunk_split(base64_encode($content));
    	}  

		if ($this->protocol == 'mail') {
			ini_set('sendmail_from', $this->from);
		
    		mail($to, $this->subject, $message, $headers);  
		} elseif ($this->protocol == 'smtp') {
			$fp = fsockopen($this->smtp_host, $this->smtp_port, $errno, $errstr, $this->smtp_timeout);	
			
			if ($fp) {
				fputs($fp, 'HELO ' . '127.0.0.1' . $eol);
				fputs($fp, 'AUTH LOGIN ' . $eol);
				fputs($fp, base64_encode($this->smtp_username) . $eol);
				fputs($fp, base64_encode($this->smtp_password) . $eol);
				fputs($fp, 'MAIL FROM: <' . $this->from . '>' . $eol);
				fputs($fp, 'RCPT TO: <' . $to . '>' . $eol);
				fputs($fp, 'DATA' . $eol);
				fputs($fp, 'To: ' . $to . $eol . 'Subject: ' . $this->subject . $eol . $headers . $eol . $eol . $message . $eol . $eol . '.' . $eol);
				fputs($fp, 'QUIT' . $eol);
				fputs($fp, base64_encode($this->smtp_username) . $eol);
			}
		}
	} 
}
?>
to use it its:

$mail = new Mail('smtp', 'host', 'username', 'password');
$mail->setTo();
$mail->setFrom();
$mail->setSender();
$mail->setSubject('This is a test');
$mail->setHtml('<p>This is a test</p>');
$mail->send();

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by ssk » Tue Jul 21, 2009 8:42 am

Hi Daniel,

Thank you for taking a look at this. I replaced the code in sytem/library/mail.php with the code you put up. I'm not sure what to do with the next part "to use it" though. Where do I plug that in?

$mail = new Mail('smtp', 'host', 'username', 'password'); and do I fill in the information between the italics here?
$mail->setTo();
$mail->setFrom();
$mail->setSender();
$mail->setSubject('This is a test');
$mail->setHtml('<p>This is a test</p>');
$mail->send();

Of course I tried to "Contact Us" again anyway, got this error message:

Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay for xxxx@xxxx.com in D:\Hosting\.......\html\test\system\library\mail.php on line 140

Warning: Cannot modify header information - headers already sent by (output started at D:\Hosting\....\html\test\system\library\mail.php:140) in D:\Hosting\.....\html\test\system\engine\controller.php on line 23

ssk
Newbie

Posts

Joined
Fri Jul 17, 2009 6:16 am

Post by Daniel » Tue Jul 21, 2009 8:56 am

look at the latest version it has smtp intergrated.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm
Who is online

Users browsing this forum: No registered users and 12 guests