Post by broopenc3 » Mon Sep 10, 2018 3:20 pm

Hello Opencart Forum,

I am trying to create a php file that alongside other actions, like sending an SMS (which is working fine), the script also needs to send an email (it fails obviously).

Simple as that.
I had some problems trying to require_once the config, startup and library/email files but I fixed it and now I do not get any error, however emails are not sent.


The PHP file runs in the same server and directory with Opencart 1.5 but lets say I want to create a standalone .php file that sends emails.

Code: Select all

<?php
$email_address = "address@mail.com";
$message  = "My Message";
	
require_once('config.php');
require_once(DIR_SYSTEM . 'startup.php');
$config = new Config();

$mail = new Mail();
$mail->protocol = $config->get('config_mail_protocol');
$mail->parameter = $config->get('config_mail_parameter');
$mail->hostname = $config->get('config_smtp_host');
$mail->username = $config->get('config_smtp_username');
$mail->password = $config->get('config_smtp_password');
$mail->port = $config->get('config_smtp_port');
$mail->timeout = $config->get('config_smtp_timeout');				
$mail->setTo($email_address);
$mail->setFrom($config->get('config_email'));
$mail->setSender("My Store");
$mail->setSubject("My Subject");
$mail->setText($message);
$mail->send();
?>
I do not know how to echo the properties of Mail and Config to know what I need to do so I came here for help.

New member

Posts

Joined
Fri Mar 16, 2018 7:09 pm

Post by pprmkr » Mon Sep 10, 2018 8:37 pm

You did not read the settings from database.

Code: Select all

<?php

require_once('config.php');
require_once(DIR_SYSTEM . 'startup.php');

$config = new Config();

// Database 
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);

// Store
if (isset($_SERVER['HTTPS']) && (($_SERVER['HTTPS'] == 'on') || ($_SERVER['HTTPS'] == '1'))) {
	$store_query = $db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`ssl`, 'www.', '') = '" . $db->escape('https://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'");
} else {
	$store_query = $db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`url`, 'www.', '') = '" . $db->escape('http://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'");
}

if ($store_query->num_rows) {
	$config->set('config_store_id', $store_query->row['store_id']);
} else {
	$config->set('config_store_id', 0);
}
		
// Settings
$query = $db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE store_id = '0' OR store_id = '" . (int)$config->get('config_store_id') . "' ORDER BY store_id ASC");

foreach ($query->rows as $setting) {
	if (!$setting['serialized']) {
		$config->set($setting['key'], $setting['value']);
	} else {
		$config->set($setting['key'], unserialize($setting['value']));
	}
}

if (!$store_query->num_rows) {
	$config->set('config_url', HTTP_SERVER);
	$config->set('config_ssl', HTTPS_SERVER);	
}

// now all stored config settings are available


print_r($config);

User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by broopenc3 » Wed Sep 12, 2018 3:32 pm

pprmkr wrote:
Mon Sep 10, 2018 8:37 pm
You did not read the settings from database.
Yes indeed! Your fix was spot on! Thanx for the help! ;)

New member

Posts

Joined
Fri Mar 16, 2018 7:09 pm
Who is online

Users browsing this forum: Amazon [Bot] and 199 guests