PHP Help regarding OpenCart

Associate
Joined
9 Jul 2007
Posts
512
Location
Ramsgate, Kent
Hey guys, have basically installed a fresh copy of OpenCart (open source ecommerce) onto my webserver. Having done this, the contact page doesn't seem to work unfortunately.

I have managed to get the mail actually sent, but it doesn't send the 'email' that the user has inputted into the form, meaning a reply to them is impossible.

Here you can see the contact page:
http://flashtees.co.uk/index.php?controller=contact

Here is the PHP file that physically deals with the mail (Mail.php)

Code:
<?php 
class Mail {
	var $to;
  	var $from;
  	var $sender;
  	var $subject;
  	var $charset;
  	var $text;
  	var $html;
  	var $attachments = array();
	  
  	function setTo($to) {
    	$this->to = $to;
  	}
  
  	function setFrom($from) {
    	$this->from = $from;
  	}
    
  	function setSender($sender) {
    	$this->sender = $sender;
  	}

  	function setEmail() {
    	$this->email = $email;
  	}
  
  	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($attachments) {
    	$this->attachments[] = $attachments;
  	}
  
  	function send() {	
    	if (!$this->to) {
      		exit('Error: To not set');
    	}
	
    	if (!$this->from) {
      		exit('Error: From not set');
    	}
    
    	if (!$this->sender) {
      		exit('Error: Sender not set');
    	}
		
		if (!$this->subject) {
      		exit('Error: Subject not set');
    	}
			
		if ((!$this->text) && (!$this->html)) {
      		exit('Error: Message not set');
    	}

		if (is_array($this->to)) {
      		$to = implode($this->to, ',');
    	} else {
      		$to = $this->to;
    	}
	  	
		if ($this->charset) {
	  		$charset = $this->charset;
		} else { 
	  		$charset = 'utf-8';
		}
	  
		$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  = 'X-Mailer: PHP/' . phpversion() . $eol;  
    	$headers .= 'MIME-Version: 1.0' . $eol; 
    	$headers .= 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' . $eol . $eol;   
	
		if (!$this->html) {
	  		$message  = '--' . $boundary . $eol;  
	  		$message .= 'Content-Type: text/plain; charset="' . $charset . '"' . $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="' . $charset . '"' . $eol; 
	  		$message .= 'Content-Transfer-Encoding: base64' . $eol . $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="' . $charset . '"' . $eol; 
      		$message .= 'Content-Transfer-Encoding: base64' . $eol . $eol;
	  		$message .= chunk_split(base64_encode($this->html)); 	  
		}
	
    	foreach ($this->attachments as $attachment) {  
      		$filename = basename($attachment);  
      		$handle   = fopen($attachment, "r"); 
      		$content  = '';  
      
	  		while (!feof($handle)) {  
        		$content .= fgets($handle, 1024);  
      		}  
      
	  		$content = chunk_split(base64_encode($content));  
      
	  		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 .= $content;  
    	}  
	ini_set("SMTP","smtp.flashtees.co.uk");
	ini_set("smtp_port","25");
	ini_set("sendmail_from", "[email protected]");
      mail("[email protected]",  $this->subject, $message, $headers);
	} 
}
?>

The final 5-6 lines of this code have been added by myself to try to actually get the emails sent from the form.

Any help would be appreciated on this, thanks.
 
Do you have the option in the set up of the cart software to use PHP mail instead of using the SMTP way out?

If you look in your error logs is there anything pointing out what is wrong - I use directadmin and live in the error logs finding out what I did wrong :D
 
Back
Top Bottom