Uncaught error after submitting the requet for price form - php

We are using open cart for website development and recently i have changed Reply To mail address as i wanted while sending confirmation mail to admin when a user registered on website saying new customer has registered on website,now i am getting the error after submitting another form (request for Price).
Uncaught exception 'Exception' with message 'Error: E-Mail to required!' in /var/www/html/neon_opencart/system/library/mail.php:60 Stack trace: #0 /var/www/html/neon_opencart/catalog/controller/product/category.php(124): Mail->send() #1 [internal function]: ControllerProductCategory->index() #2 /var/www/html/neon_opencart/system/storage/modification/system/engine/action.php(44): call_user_func_array(Array, Array) #3 /var/www/html/neon_opencart/catalog/controller/startup/router.php(25): Action->execute(Object(Registry)) #4 [internal function]: ControllerStartupRouter->index() #5 /var/www/html/neon_opencart/system/storage/modification/system/engine/action.php(44): call_user_func_array(Array, Array) #6 /var/www/html/neon_opencart/system/engine/front.php(34): Action->execute(Object(Registry)) #7 /var/www/html/neon_opencart/system/engine/front.php(29): Front->execute(Object(Action)) #8 /var/www/html/neon_opencart/system/framework.php(99): Front->dispatch(Object(Action), Object(Action)) #9 /var/www/html/neon_openca in /var/www/html/neon_opencart/system/library/mail.php on line 60
Please have a look at the error,here is my code
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
$mail->setTo($this->config->get('config_email'));
$mail->setFrom($this->config->get('config_email'));
$mail->setReplyTo('example#domain.com');
$mail->setSender(html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'));
$mail->setSubject(html_entity_decode($this->language->get('text_new_customer'), ENT_QUOTES, 'UTF-8') . '-' . date('d-m-y'));
//$mail->sethtml($message);
$mail->setText($message_admin);
$mail->send();

Related

UnauthorizedException in reading emails with Oauth 2 using EWS

I am trying to load email list using oauth 2. Following is my code:
<?php
require_once "vendor/autoload.php";
use src\API\Type;
use garethp\ews\MailAPI as API;
$token='EwA......'; //access token
$api = API::withCallbackToken('outlook.office365.com', $token);
$mail = $api->getMailItems();
foreach ($mail as $email) {
$email = $api->getItem($email->getItemId());
$email_id=$email->getItemId();
$subject = $email->getSubject();
$sender = $email->getSender()->getMailbox()->getEmailAddress();
$body = (string) $email->getBody();
echo $body;
}
but getting response as follows:
Fatal error: Uncaught garethp\ews\API\Exception\UnauthorizedException
in
C:\inetpub\wwwroot\bephpforTteam\New\php_ews\php-ews-master\src\API\ExchangeWebServices.php:438
Stack trace: #0
C:\inetpub\wwwroot\bephpforTteam\New\php_ews\php-ews-master\src\API\ExchangeWebServices.php(356):
garethp\ews\API\ExchangeWebServices->handleNonSuccessfulResponses(NULL,
401) #1
C:\inetpub\wwwroot\bephpforTteam\New\php_ews\php-ews-master\src\API\ExchangeWebServices\MiddlewareFactory.php(57):
garethp\ews\API\ExchangeWebServices->processResponse(NULL) #2
C:\inetpub\wwwroot\bephpforTteam\New\php_ews\php-ews-master\src\API\ExchangeWebServices.php(497):
garethp\ews\API\ExchangeWebServices->garethp\ews\API\ExchangeWebServices{closure}(Object(garethp\ews\API\MiddlewareRequest),
Object(Closure)) #3
C:\inetpub\wwwroot\bephpforTteam\New\php_ews\php-ews-master\src\API\ExchangeWebServices\MiddlewareFactory.php(66):
garethp\ews\API\ExchangeWebServices->garethp\ews\API{closure}(Object(garethp\ews\API\MiddlewareRequest)) #4 C:\inetpub\wwwroot\bephpforTt in C:\inetpub\wwwroot\bephpforTteam\New\php_ews\php-ews-master\src\API\ExchangeWebServices.php
on line 438

Uncaught exception 'Exception' with message 'error setting certificate verify locations: CAfile: \twitter-api-php-master\TwitterAPIExchange.php:321

I am developing a custom wp plugin that deals with twitter so I am using this as repository https://github.com/J7mbo/twitter-api-php
This is my code for the shortcode:
function ct_twitter_shortcode_func( $atts ){
ob_start();
include_once '/includes/twitter-api-php-master/TwitterAPIExchange.php';
$ct_twitter_keys = get_option("ct_twitter_keys");
$settings = array(
'oauth_access_token' => $ct_twitter_keys["OAUTH_ACCESS_TOKEN"],
'oauth_access_token_secret' => $ct_twitter_keys["OAUTH_ACCESS_TOKEN_SECRET"],
'consumer_key' => $ct_twitter_keys["CONSUMER_KEY"],
'consumer_secret' => $ct_twitter_keys["CONSUMER_SECRET"]
);
//echo dirname(__FILE__) . '/cacert.pem';
$url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
$requestMethod = "GET";
$getfield = '?screen_name=bikegearup&count=20';
$twitter = new TwitterAPIExchange($settings);
$twitter = new TwitterAPIExchange($settings);
echo $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(true, array(CURLOPT_CAINFO => '/includes/twitter-api-php-master/cacert.pem'));
return ob_get_clean();
}
add_shortcode( 'ct_twitter', 'ct_twitter_shortcode_func' );
but I got this kind of error:
Fatal error: Uncaught exception 'Exception' with message 'error setting certificate verify locations: CAfile: /includes/twitter-api-php-master/cacert.pem CApath: none' in C:\xampp\htdocs\pluto\wp-content\plugins\ct-socials\shortcodes\ct-twitter\includes\twitter-api-php-master\TwitterAPIExchange.php:321 Stack trace: #0 C:\xampp\htdocs\pluto\wp-content\plugins\ct-socials\shortcodes\ct-twitter\class-fw-shortcode-ct-twitter.php(23): TwitterAPIExchange->performRequest(true, Array) #1 [internal function]: ct_twitter_shortcode_func(Array, '', 'ct_twitter') #2 C:\xampp\htdocs\pluto\wp-includes\shortcodes.php(345): call_user_func('ct_twitter_shor...', Array, '', 'ct_twitter') #3 [internal function]: do_shortcode_tag(Array) #4 C:\xampp\htdocs\pluto\wp-includes\shortcodes.php(223): preg_replace_callback('/\[(\[?)(ct_soc...', 'do_shortcode_ta...', '[ct_twitter sty...') #5 [internal function]: do_shortcode('[ct_twitter sty...') #6 C:\xampp\htdocs\pluto\wp-includes\class-wp-hook.php(298): call_user_func_array('do_shortcode', Arra in C:\xampp\htdocs\pluto\wp-content\plugins\ct-socials\shortcodes\ct-twitter\includes\twitter-api-php-master\TwitterAPIExchange.php on line 321
I also tried to include https://curl.haxx.se/ca/cacert.pem but still it won't work.. can anyone help me with this?
any help will be appreciated, thanks in advance...

Slim 3 upload image to server path

Hi im new in slim 3 framework (Api for mobile) i would like to know how to upload an image to a server, e seacrh for examples didnt find much, this is the code i have but it does not work.Any help would be great thanks.
$app->post('/photo', function ($request, $response) use ($app) {
$files = $request->getUploadedFiles();
if (empty($files['newfile'])) {
throw new Exception('Expected a newfile');
}
$newfile = $files['newfile'];
if ($newfile->getError() === UPLOAD_ERR_OK) {
$uploadFileName = $newfile->getClientFilename();
$newfile->moveTo("../photos/");
}
});
The error it gives me
<h1>Slim Application Error</h1>
<p>The application could not run because of the following error:</p>
<h2>Details</h2>
<div>
<strong>Type:</strong> Error
</div>
<div>
<strong>Message:</strong> Call to a member function getError() on null
</div>
<div>
<strong>File:</strong> /home/bitstudi/public_html/api_pricegram/public/index.php
</div>
<div>
<strong>Line:</strong> 155
</div>
<h2>Trace</h2>
#0 [internal function]: Closure->{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#1 /home/bitstudi/public_html/api_pricegram/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(41): call_user_func(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#2 /home/bitstudi/public_html/api_pricegram/vendor/slim/slim/Slim/Route.php(344): Slim\Handlers\Strategies\RequestResponse->__invoke(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#3 /home/bitstudi/public_html/api_pricegram/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(122): Slim\Route->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#4 /home/bitstudi/public_html/api_pricegram/vendor/slim/slim/Slim/Route.php(316): Slim\Route->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#5 /home/bitstudi/public_html/api_pricegram/vendor/slim/slim/Slim/App.php(476): Slim\Route->run(Object(Slim\Http\Request), Object(Slim\Http\Response))
#6 /home/bitstudi/public_html/api_pricegram/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(122): Slim\App->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#7 /home/bitstudi/public_html/api_pricegram/vendor/slim/slim/Slim/App.php(370): Slim\App->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#8 /home/bitstudi/public_html/api_pricegram/vendor/slim/slim/Slim/App.php(295): Slim\App->process(Object(Slim\Http\Request), Object(Slim\Http\Response))
#9 /home/bitstudi/public_html/api_pricegram/public/index.php(161): Slim\App->run()
#10 {main}
i solved like this
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
use Slim\Http\UploadedFile;
require '../vendor/autoload.php';
$app = new \Slim\App([
'settings' => [
'displayErrorDetails' => true
]
]);
$container = $app->getContainer();
$container['upload_directory'] ='../photos/';
$app->post('/photo', function (Request $request, Response $response) use ($app) {
$directory = $this->get('upload_directory');
$uploadedFiles = $request->getUploadedFiles();
$uploadedFile = $uploadedFiles['picture'];
if($uploadedFile->getError() === UPLOAD_ERR_OK) {
$filename = moveUploadedFile($directory, $uploadedFile);
$response->write('uploaded ' . $filename . '<br/>');
}
});
function moveUploadedFile($directory, UploadedFile $uploadedFile){
$extension = pathinfo($uploadedFile->getClientFilename(),
PATHINFO_EXTENSION);
$basename = bin2hex(random_bytes(8));
$filename = sprintf('%s.%0.8s', $basename, $extension);
$uploadedFile->moveTo($directory . DIRECTORY_SEPARATOR . $filename);
return $filename;
}
$app->run();

Get users for all accounts with Google Analytics api

I am having problems getting a list of users for accounts
If I put the account number in the try me page (https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/accountUserLinks/list) it works
$client = new Google_Client();
$client->setAuthConfigFile($_SERVER['DOCUMENT_ROOT'] . '/client_secrets.json');
$client->addScope(Google_Service_Analytics::ANALYTICS_MANAGE_USERS);
$client=gaGetClient();
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
$analytics = new Google_Service_Analytics($client);
//this doesn't work
$accountUserlinks=$analytics->management_accountUserLinks->listManagementAccountUserLinks('123456');
//this works
$man_accounts = $analytics->management_accounts->listManagementAccounts();
$accounts = [];
foreach ($man_accounts['items'] as $account) {
$accounts[] = [ 'id' => $account['id'], 'name' => $account['name'] ];
echo $account['name'] . " (" . $account['id'] . ")<br/>";
}
}
I get this error message
Fatal error: Uncaught exception 'Google_Service_Exception' with
message 'Error calling GET
https://www.googleapis.com/analytics/v3/management/accounts/123456/entityUserLinks:
(403) Insufficient Permission' in
/home/grant/www/productaudit.hcpservices.co.uk/htdocs/current/google-api-php-client/src/Google/Http/REST.php:110
Stack trace: #0
/home/grant/www/productaudit.hcpservices.co.uk/htdocs/current/google-api-php-client/src/Google/Http/REST.php(62):
Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request),
Object(Google_Client)) #1 [internal function]:
Google_Http_REST::doExecute(Object(Google_Client),
Object(Google_Http_Request)) #2
/home/grant/www/productaudit.hcpservices.co.uk/htdocs/current/google-api-php-client/src/Google/Task/Runner.php(174):
call_user_func_array(Array, Array) #3
/home/grant/www/productaudit.hcpservices.co.uk/htdocs/current/google-api-php-client/src/Google/Http/REST.php(46):
Google_Task_Runner->run() #4
/home/grant/www/productaudit.hcpservices.co.uk/htdocs/current/google-api-php-client/src/Goo
in
/home/grant/www/productaudit.hcpservices.co.uk/htdocs/current/google-api-php-client/src/Google/Http/REST.php
on line 110
Can anyone think what I am doing wrong. I am thinking it is a scope issue, but I have stated my scopes
Thanks
Grant

Swift mailer not working in server but working in local machine

My code is:
require_once 'Swift-5.0.3/lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp-mail.outlook.com', 587, "tls")
->setUsername('username#outlook.com')
->setPassword('password');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Test')
->setFrom(array('demo#gmail.com' => 'Dpu'))
->setTo(array('demo2#gmail.com'))
->setBody('test body');
$result = $mailer->send($message);
if($result)
echo "success";
else
echo "Failed";
The code is working and mail is sent when I working in local machine. But in server I got the error and mail was not sent.
The error is:
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Failed to authenticate on SMTP server with username "username#outlook.com" using 2 possible authenticators' in /home/xxx/public_html/xxx/Mail/Swift-5.0.3/lib/classes/Swift/Transport/Esmtp/AuthHandler.php:184 Stack trace: #0 /home/xxx/public_html/xxx/Mail/Swift-5.0.3/lib/classes/Swift/Transport/EsmtpTransport.php(312): Swift_Transport_Esmtp_AuthHandler->afterEhlo(Object(Swift_SmtpTransport)) #1 /home/xxx/public_html/xxx/Mail/Swift-5.0.3/lib/classes/Swift/Transport/AbstractSmtpTransport.php(120): Swift_Transport_EsmtpTransport->_doHeloCommand() #2 /home/xxx/public_html/xxx/Mail/Swift-5.0.3/lib/classes/Swift/Mailer.php(80): Swift_Transport_AbstractSmtpTransport->start() #3 /home/xxx/public_html/xxx/Mail/mail.php(19): Swift_Mailer->send(Object(Swift_Message)) #4 {main} thrown in /home/xxx/public_html/xxx/Mail/Swift-5.0.3/lib/classes/Swift/Transport/Esmtp/AuthHandler.php on line 184
Please help me...

Categories