Post by psytanium » Sun Oct 07, 2018 11:42 pm

Hello,

When I submit contact form i get this error "Notice: Error: Could not load mail adaptor"
Im using Opencar 3.0.2.0
I tried to disable theme and all extensions, but nothing work.

Thanks for any help.

Active Member

Posts

Joined
Fri Nov 27, 2015 2:07 am

Post by psytanium » Mon Oct 08, 2018 3:04 pm

I found someone posted new mail.php file here on this forum and it worked. My mail.php was this :

Code: Select all

<?php
class Mail {
	protected $to;
	protected $from;
	protected $sender;
	protected $reply_to;
	protected $subject;
	protected $text;
	protected $html;
	protected $attachments = array();
	public $protocol = 'mail';
	public $smtp_hostname;
	public $smtp_username;
	public $smtp_password;
	public $smtp_port = 25;
	public $smtp_timeout = 5;
	public $verp = false;
	public $parameter = '';

	public function __construct($config = array()) {
		foreach ($config as $key => $value) {
			$this->$key = $value;
		}
	}

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

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

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

	public function setReplyTo($reply_to) {
		$this->reply_to = $reply_to;
	}

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

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

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

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

	public function send() {
		if (!$this->to) {
			throw new \Exception('Error: E-Mail to required!');
		}

		if (!$this->from) {
			throw new \Exception('Error: E-Mail from required!');
		}

		if (!$this->sender) {
			throw new \Exception('Error: E-Mail sender required!');
		}

		if (!$this->subject) {
			throw new \Exception('Error: E-Mail subject required!');
		}

		if ((!$this->text) && (!$this->html)) {
			throw new \Exception('Error: E-Mail message required!');
		}

		if (is_array($this->to)) {
			$to = implode(',', $this->to);
		} else {
			$to = $this->to;
		}

		$boundary = '----=_NextPart_' . md5(time());

		$header = 'MIME-Version: 1.0' . PHP_EOL;

		if ($this->protocol != 'mail') {
			$header .= 'To: <' . $to . '>' . PHP_EOL;
			$header .= 'Subject: =?UTF-8?B?' . base64_encode($this->subject) . '?=' . PHP_EOL;
		}

		$header .= 'Date: ' . date('D, d M Y H:i:s O') . PHP_EOL;
		$header .= 'From: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->from . '>' . PHP_EOL;
		
		if (!$this->reply_to) {
			$header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->from . '>' . PHP_EOL;
		} else {
			$header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->reply_to) . '?= <' . $this->reply_to . '>' . PHP_EOL;
		}
		
		$header .= 'Return-Path: ' . $this->from . PHP_EOL;
		$header .= 'X-Mailer: PHP/' . phpversion() . PHP_EOL;
		$header .= 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' . PHP_EOL . PHP_EOL;

		if (!$this->html) {
			$message  = '--' . $boundary . PHP_EOL;
			$message .= 'Content-Type: text/plain; charset="utf-8"' . PHP_EOL;
			$message .= 'Content-Transfer-Encoding: 8bit' . PHP_EOL . PHP_EOL;
			$message .= $this->text . PHP_EOL;
		} else {
			$message  = '--' . $boundary . PHP_EOL;
			$message .= 'Content-Type: multipart/alternative; boundary="' . $boundary . '_alt"' . PHP_EOL . PHP_EOL;
			$message .= '--' . $boundary . '_alt' . PHP_EOL;
			$message .= 'Content-Type: text/plain; charset="utf-8"' . PHP_EOL;
			$message .= 'Content-Transfer-Encoding: 8bit' . PHP_EOL . PHP_EOL;

			if ($this->text) {
				$message .= $this->text . PHP_EOL;
			} else {
				$message .= 'This is a HTML email and your email client software does not support HTML email!' . PHP_EOL;
			}

			$message .= '--' . $boundary . '_alt' . PHP_EOL;
			$message .= 'Content-Type: text/html; charset="utf-8"' . PHP_EOL;
			$message .= 'Content-Transfer-Encoding: 8bit' . PHP_EOL . PHP_EOL;
			$message .= $this->html . PHP_EOL;
			$message .= '--' . $boundary . '_alt--' . PHP_EOL;
		}

		foreach ($this->attachments as $attachment) {
			if (file_exists($attachment)) {
				$handle = fopen($attachment, 'r');

				$content = fread($handle, filesize($attachment));

				fclose($handle);

				$message .= '--' . $boundary . PHP_EOL;
				$message .= 'Content-Type: application/octet-stream; name="' . basename($attachment) . '"' . PHP_EOL;
				$message .= 'Content-Transfer-Encoding: base64' . PHP_EOL;
				$message .= 'Content-Disposition: attachment; filename="' . basename($attachment) . '"' . PHP_EOL;
				$message .= 'Content-ID: <' . urlencode(basename($attachment)) . '>' . PHP_EOL;
				$message .= 'X-Attachment-Id: ' . urlencode(basename($attachment)) . PHP_EOL . PHP_EOL;
				$message .= chunk_split(base64_encode($content));
			}
		}

		$message .= '--' . $boundary . '--' . PHP_EOL;

		if ($this->protocol == 'mail') {
			ini_set('sendmail_from', $this->from);

			if ($this->parameter) {
				mail($to, '=?UTF-8?B?' . base64_encode($this->subject) . '?=', $message, $header, $this->parameter);
			} else {
				mail($to, '=?UTF-8?B?' . base64_encode($this->subject) . '?=', $message, $header);
			}
		} elseif ($this->protocol == 'smtp') {
			if (substr($this->smtp_hostname, 0, 3) == 'tls') {
				$hostname = substr($this->smtp_hostname, 6);
			} else {
				$hostname = $this->smtp_hostname;
			}

			$handle = fsockopen($hostname, $this->smtp_port, $errno, $errstr, $this->smtp_timeout);

			if (!$handle) {
				throw new \Exception('Error: ' . $errstr . ' (' . $errno . ')');
			} else {
				if (substr(PHP_OS, 0, 3) != 'WIN') {
					socket_set_timeout($handle, $this->smtp_timeout, 0);
				}
	
		
				while ($line = fgets($handle, 515)) {
					if (substr($line, 3, 1) == ' ') {
						break;
					}
				}

				fputs($handle, 'EHLO ' . getenv('SERVER_NAME') . "\r\n");

				$reply = '';

				while ($line = fgets($handle, 515)) {
					$reply .= $line;

					//some SMTP servers respond with 220 code before responding with 250. hence, we need to ignore 220 response string
					if (substr($reply, 0, 3) == 220 && substr($line, 3, 1) == ' ') {
						$reply = '';
						continue;
					}
					else if (substr($line, 3, 1) == ' ') {
						break;
					}
				}

				if (substr($reply, 0, 3) != 250) {
					throw new \Exception('Error: EHLO not accepted from server!');
				}

				if (substr($this->smtp_hostname, 0, 3) == 'tls') {
					fputs($handle, 'STARTTLS' . "\r\n");

					$reply = '';

					while ($line = fgets($handle, 515)) {
						$reply .= $line;

						if (substr($line, 3, 1) == ' ') {
							break;
						}
					}

					if (substr($reply, 0, 3) != 220) {
						throw new \Exception('Error: STARTTLS not accepted from server!');
					}

					stream_socket_enable_crypto($handle, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
				}

				if (!empty($this->smtp_username)  && !empty($this->smtp_password)) {
					fputs($handle, 'EHLO ' . getenv('SERVER_NAME') . "\r\n");

					$reply = '';

					while ($line = fgets($handle, 515)) {
						$reply .= $line;

						if (substr($line, 3, 1) == ' ') {
							break;
						}
					}

					if (substr($reply, 0, 3) != 250) {
						throw new \Exception('Error: EHLO not accepted from server!');
					}

					fputs($handle, 'AUTH LOGIN' . "\r\n");

					$reply = '';

					while ($line = fgets($handle, 515)) {
						$reply .= $line;

						if (substr($line, 3, 1) == ' ') {
							break;
						}
					}

					if (substr($reply, 0, 3) != 334) {
						throw new \Exception('Error: AUTH LOGIN not accepted from server!');
					}

					fputs($handle, base64_encode($this->smtp_username) . "\r\n");

					$reply = '';

					while ($line = fgets($handle, 515)) {
						$reply .= $line;

						if (substr($line, 3, 1) == ' ') {
							break;
						}
					}

					if (substr($reply, 0, 3) != 334) {
						throw new \Exception('Error: Username not accepted from server!');
					}

					fputs($handle, base64_encode($this->smtp_password) . "\r\n");

					$reply = '';

					while ($line = fgets($handle, 515)) {
						$reply .= $line;

						if (substr($line, 3, 1) == ' ') {
							break;
						}
					}

					if (substr($reply, 0, 3) != 235) {
						throw new \Exception('Error: Password not accepted from server!');
					}
				} else {
					fputs($handle, 'HELO ' . getenv('SERVER_NAME') . "\r\n");

					$reply = '';

					while ($line = fgets($handle, 515)) {
						$reply .= $line;

						if (substr($line, 3, 1) == ' ') {
							break;
						}
					}

					if (substr($reply, 0, 3) != 250) {
						throw new \Exception('Error: HELO not accepted from server!');
					}
				}

				if ($this->verp) {
					fputs($handle, 'MAIL FROM: <' . $this->from . '>XVERP' . "\r\n");
				} else {
					fputs($handle, 'MAIL FROM: <' . $this->from . '>' . "\r\n");
				}

				$reply = '';

				while ($line = fgets($handle, 515)) {
					$reply .= $line;

					if (substr($line, 3, 1) == ' ') {
						break;
					}
				}

				if (substr($reply, 0, 3) != 250) {
					throw new \Exception('Error: MAIL FROM not accepted from server!');
				}

				if (!is_array($this->to)) {
					fputs($handle, 'RCPT TO: <' . $this->to . '>' . "\r\n");

					$reply = '';

					while ($line = fgets($handle, 515)) {
						$reply .= $line;

						if (substr($line, 3, 1) == ' ') {
							break;
						}
					}

					if ((substr($reply, 0, 3) != 250) && (substr($reply, 0, 3) != 251)) {
						throw new \Exception('Error: RCPT TO not accepted from server!');
					}
				} else {
					foreach ($this->to as $recipient) {
						fputs($handle, 'RCPT TO: <' . $recipient . '>' . "\r\n");

						$reply = '';

						while ($line = fgets($handle, 515)) {
							$reply .= $line;

							if (substr($line, 3, 1) == ' ') {
								break;
							}
						}

						if ((substr($reply, 0, 3) != 250) && (substr($reply, 0, 3) != 251)) {
							throw new \Exception('Error: RCPT TO not accepted from server!');
						}
					}
				}

				fputs($handle, 'DATA' . "\r\n");

				$reply = '';

				while ($line = fgets($handle, 515)) {
					$reply .= $line;

					if (substr($line, 3, 1) == ' ') {
						break;
					}
				}

				if (substr($reply, 0, 3) != 354) {
					throw new \Exception('Error: DATA not accepted from server!');
				}

				// According to rfc 821 we should not send more than 1000 including the CRLF
				$message = str_replace("\r\n", "\n", $header . $message);
				$message = str_replace("\r", "\n", $message);

				$lines = explode("\n", $message);

				foreach ($lines as $line) {
					$results = str_split($line, 998);

					foreach ($results as $result) {
						if (substr(PHP_OS, 0, 3) != 'WIN') {
							fputs($handle, $result . "\r\n");
						} else {
							fputs($handle, str_replace("\n", "\r\n", $result) . "\r\n");
						}
					}
				}

				fputs($handle, '.' . "\r\n");

				$reply = '';

				while ($line = fgets($handle, 515)) {
					$reply .= $line;

					if (substr($line, 3, 1) == ' ') {
						break;
					}
				}

				if (substr($reply, 0, 3) != 250) {
					throw new \Exception('Error: DATA not accepted from server!');
				}

				fputs($handle, 'QUIT' . "\r\n");

				$reply = '';

				while ($line = fgets($handle, 515)) {
					$reply .= $line;

					if (substr($line, 3, 1) == ' ') {
						break;
					}
				}

				if (substr($reply, 0, 3) != 221) {
					throw new \Exception('Error: QUIT not accepted from server!');
				}

				fclose($handle);
			}
		}
	}
}
Replaced with this :

Code: Select all

<?php
final class Mail {
	protected $to;
	protected $from;
	protected $sender;
	protected $subject;
	protected $text;
	protected $html;
	protected $attachments = array();
	public $protocol = 'mail';
	public $separator = ',';
	public $hostname;
	public $username;
	public $password;
	public $port = 25;
	public $timeout = 5;
	public $newline = "\n";
	public $crlf = "\r\n";
	public $verp = FALSE;
	public $parameter = '';
	public function isValidEmail($email){
		$pattern = '/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i';
		if (!preg_match($pattern,$email)) {
			return false;
		}
		return true;
	}
	public function setTo($to) {
		if (is_array($to)) {
			$this->to = $to;
		} else {
			$this->to = explode($this->separator,$to);
		}
		foreach ($this->to as $to){
			if (!$this->isValidEmail($to)) {
				exit('Error: E-Mail Address does not appear to be valid!');
			}
		}
	}
   
	public function setFrom($from) {
		$fromTmp = explode($this->separator,$from);
		$from = array_shift($fromTmp);
		if (!$this->isValidEmail($from)) {
			exit('Error: E-Mail Address does not appear to be valid!');
		}
		$this->from = $from;
	}
	
	public function addheader($header, $value) {
		$this->headers[$header] = $value;
	}
	
	public function setSender($sender) {
		$sender="=?UTF-8?B?".base64_encode($sender)."?=";
		$this->sender = $sender;
	}
	
	public function setSubject($subject) {
		$subject = preg_replace('/(,|:|\.|\"|\'|!|&|-)/s',' ',$subject);
		$subject ="=?UTF-8?B?".base64_encode($subject)."?=";
		$this->subject = $subject;
	}
	
	public function setText($text) {
		$text = nl2br($text);
		$this->text = $text;
	}
	
	public function setHtml($html) {
		$this->html = $html;
	}
	
	public function addAttachment($file, $filename = '') {
		if (!$filename) {
			$filename = basename($file);
		}
	  
		$this->attachments[] = array(
			'filename' => $filename,
			'file'     => $file
		);
	}
	
	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 ($this->protocol == 'smtp'&&$this->hostname&&$this->username) {
			if (!$this->html) {
				$message =$this->text;
			} else {
				$message = $this->html;
			}

			$mail  = new PHPMailer();

			$mail->IsSMTP();
			$mail->CharSet       = "utf-8";
			$mail->Host       = $this->hostname;
			$mail->SMTPAuth       = true;
			$mail->Username       = $this->username;
			$mail->setFrom('contact@yourdomain.com', 'Your Name');
			$mail->Password       = $this->password;
			$mail->Subject    = $this->subject;
			$mail->MsgHTML($message);
			$mail->SMTPSecure = "tls";
			$mail->Port = 587;


			foreach ($this->attachments as $attachment) {
				$mail->AddAttachment($attachment['file'],$attachment['filename']);
			}
			foreach ($this->to as $toTmp){
				$mail->AddAddress($toTmp);
			}
			$mail->Send();
		}else{
			$boundary = '----=_NextPart_' . md5(rand());

			if (strpos(PHP_OS, 'WIN') === false) {
				$eol = $this->newline;
			} else {
				$eol = $this->crlf;
			}

			$headers  = 'From: ' . $this->sender . '<' . $this->from . '>' . $eol;
			$headers .= 'Reply-To: ' . $this->sender . '<' . $this->from . '>' . $eol;
			$headers .= 'Return-Path: ' . $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) {
				if (file_exists($attachment['file'])) {
					$handle = fopen($attachment['file'], 'r');
					$content = fread($handle, filesize($attachment['file']));
			
					fclose($handle); 
			
					$message .= '--' . $boundary . $eol;
					$message .= 'Content-Type: application/octetstream' . $eol;   
					$message .= 'Content-Transfer-Encoding: base64' . $eol;
					$message .= 'Content-Disposition: attachment; filename="' . basename($attachment['filename']) . '"' . $eol;
					$message .= 'Content-ID: <' . basename($attachment['filename']) . '>' . $eol . $eol;
					$message .= chunk_split(base64_encode($content));
				}
			}
			$to = implode($this->separator, $this->to);
			if ($this->parameter) {
				mail($to, $this->subject, $message, $headers, $this->parameter);
			} else {
				mail($to, $this->subject, $message, $headers);
			}
		}
	}
}
?>

Active Member

Posts

Joined
Fri Nov 27, 2015 2:07 am

Post by straightlight » Mon Oct 08, 2018 6:48 pm

Take note the posted modifications above might be server-specifics.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by psytanium » Mon Oct 08, 2018 7:27 pm

straightlight wrote:
Mon Oct 08, 2018 6:48 pm
Take note the posted modifications above might be server-specifics.
Can you please elaborate more ? Im hosted on self managed VPS server.

Active Member

Posts

Joined
Fri Nov 27, 2015 2:07 am

Post by straightlight » Mon Oct 08, 2018 7:35 pm

It means that while this code was posted as a general solution from your perspective of view, it may also work for your server specifically or for only those that did worked particularly but not necessarily for someone else.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by psytanium » Sun Oct 28, 2018 12:57 am

I have a problem I cannot solve, the contact page cant send emails, I have Opencart 3.0.2.0
I tried to turn off all extensions and theme, but still whenever I send a mail i get this error :

Notice: Error: Could not load mail adaptor mail! in /home/lbkamacom/public_html/system/library/mail.php on line 36

The website is hosted on my vps server, along with other opencart website that have no problem at all sending emails, but all my other opencart website are 2.3.0.2

I need urgent help.. if possible.. thanks

Active Member

Posts

Joined
Fri Nov 27, 2015 2:07 am

Post by straightlight » Sun Oct 28, 2018 3:45 am

Ensure your admin - > systems - > settings - > edit settings - > mail tab is properly configured and the system/library/mail folder contains mail.php and smtp.php files.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by psytanium » Sun Oct 28, 2018 7:26 pm

straightlight wrote:
Sun Oct 28, 2018 3:45 am
Ensure your admin - > systems - > settings - > edit settings - > mail tab is properly configured and the system/library/mail folder contains mail.php and smtp.php files.
the folder contain mail.php and smtp.php files, in setting, what should I enter ? the mail engine is Mail, the other SMTP fields are empty. Should I fill the SMTP fields if my engine is Mail ?

Active Member

Posts

Joined
Fri Nov 27, 2015 2:07 am

Post by psytanium » Sun Oct 28, 2018 7:37 pm

straightlight wrote:
Sun Oct 28, 2018 3:45 am
Ensure your admin - > systems - > settings - > edit settings - > mail tab is properly configured and the system/library/mail folder contains mail.php and smtp.php files.
I tried to fill the SMTP fields and tried both engine, Mail and SMTP. still the same error, of course I did a refresh from admin modification.

SMTP Hostname : mail.domainname.com
Email and Password, inserted correctly and tested on webmail
SMTP Port 25 and tried 26

Active Member

Posts

Joined
Fri Nov 27, 2015 2:07 am

Post by psytanium » Sun Oct 28, 2018 8:15 pm

I checked all 87 Events are enabled from the back end.

Active Member

Posts

Joined
Fri Nov 27, 2015 2:07 am

Post by straightlight » Mon Oct 29, 2018 5:04 am

There are 33 events by default. Not 87. If you have higher than 33, these are due to installed extensions and … you do have quite a lot to reach this mount of events on your store.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by psytanium » Mon Oct 29, 2018 5:38 am

straightlight wrote:
Mon Oct 29, 2018 5:04 am
There are 33 events by default. Not 87. If you have higher than 33, these are due to installed extensions and … you do have quite a lot to reach this mount of events on your store.
I see.. I tried to disable all extensions and theme, but with no result.. can you give me suggestions ?

Active Member

Posts

Joined
Fri Nov 27, 2015 2:07 am
Who is online

Users browsing this forum: Baidu [Spider], drag84, pprmkr and 489 guests