Postmarkapp sending email using template PHP class - php

I am trying to send a email using postmarkapp api in php, I have managed to get it to send plain emails. I have uploaded the class to the same directory as index.php but the 'use' function seems to give me a error which is out of my knowledge.
Error:
Parse error: syntax error, unexpected '.', expecting identifier (T_STRING) in /public_html/index.php on line 5
Index.php
// Import the Postmark Client Class.
use Postmark\Models\PostmarkAttachment;
use Postmark\PostmarkClient\.php;
// Create Client
$client = new PostmarkClient("MY API KEY - CENSORED");
// Make a request
$sendResult = $client->sendEmailWithTemplate(
"sender#example.com",
"recipient#example.com",
TEMPLATEID-CENSORED,
[
"product_name" => "product_name_Value",
"name" => "name_Value",
"action_url" => "action_url_Value",
"username" => "username_Value",
"sender_name" => "sender_name_Value",
"product_address_line1" => "product_address_line1_Value",
"product_address_line2" => "product_address_line2_Value",
]);
Same directory Postmark/ I have this class (official class)
https://github.com/wildbit/postmark-php/tree/master/src/Postmark
Thanks for taking the time to read, greatly appreciated.

I think you need 'use Postmark\PostmarkClient;' instead of 'use Postmark\PostmarkClient.php;'

Related

Uncaught Error: Class 'Discord\Client' not found PHP

I am working with Php and "Discord". Right now, I am getting the following error:
Fatal error: Uncaught Error: Class 'Discord\Client' not found",But in my "src folder
Client library exists, I have "Vendor" and "src" folders, and client.php is there. Here is my code - where I am going wrong?
<?php
include __DIR__.'/vendor/autoload.php';
include 'vendor/autoload.php';
use Discord\Discord;
use Discord\Parts\Interactions\Command\Command; // Please note to use this correct namespace!
use Discord\Client;
use Discord\Parts\Interaction;
use Discord\Parts\Choices;
$client = new Client([
'public_key' => 'b81678ce3e98ff78f9387c3cxxxxxxxxxxxxxxxx',
'uri' => '0.0.0.0:80', // if you want the client to listen on a different URI
'logger' => $logger, // different logger, default will write to stdout
'loop' => $loop, // reactphp event loop, default creates a new loop
'socket_options' => [], // options to pass to the react/socket instance, default empty array
]);
You need to use
$client = new Discord([
'token' => 'b81678ce3e98ff78f9387c3cxxxxxxxxxxxxxxxx'
]);
Instead of client because library team-reflex/discord-php using Discord class instead of Client in direct interaction.
Here you can find the use cases.

QuickBooks PHP Sdk "Use" Causes Fatal Error

I am using the SDK and _Sample files to test a simple invoice creation.
I am not using composer, so the sample tells me to do this....
include('../config.php');
use QuickBooksOnline\API\Core\ServiceContext;
use QuickBooksOnline\API\DataService\DataService;
use QuickBooksOnline\API\PlatformService\PlatformService;
use QuickBooksOnline\API\Core\Http\Serialization\XmlObjectSerializer;
use QuickBooksOnline\API\Facades\Invoice;
$dataService = DataService::Configure(array(
'auth_mode' => 'oauth1',
'consumerKey' => "qyprdUSoVpIHrtBp0eDMTHGz8UXuSz",
'consumerSecret' => "TKKBfdlU1I1GEqB9P3AZlybdC8YxW5qFSbuShkG7",
'accessTokenKey' => "qyprdxccscoNl7KRbUJoaJQIhUvyXRzD9tNOlXn4DhRDoj4g",
'accessTokenSecret' => "JqkHSBKzNHbqjMq0Njbcq8fjgJSpfjMvqHVWnDOW",
'QBORealmID' => "193514464689044",
'baseUrl' => "Development"
));
So i have done this on my website, but I get the following error...
ParseError: syntax error, unexpected 'use' (T_USE)
I've literally copied the code above, into a new php file. I have successfully loaded the config.php file.
I have seen elsewhere that a "use" statement must be at the top of the file... it is!

Sending xml via soapclient in PHP

I am very new to using Web Services and understanding XML. If you feel I should read some tutorials or documentation I'd be greatful if you could supply some links.
I am trying to execute a simple function via a web service,
In the documentation that was provided I have the following information...
Web Service Input Parameters:
id , data type = xs:string , lenght: 10
password , data type = xs:string , lenght: 25
group , data type = xs:string , length: 20
orderxml , data type = xs:string , length: 2^16
I have been given sample xml for the last paramater , when I try and run the function I get the following error.
Fatal error: Uncaught SoapFault exception: [a:InternalServiceFault]
Value cannot be null. Parameter name: property in
$client = new SoapClient('http://www.example.com/service?wsdl');
$xml = '<samplexml> </samplexml>';
$response = $client->Import(
array(
'Id' => '1234',
'password' => '123456',
'group' => 'test1',
'orderxml' => $xml
));
When I try
$response = $client->Import('test', 'test');
I get the following...
I tried the second one thinking perhaps I need to send raw XML?
Fatal error: Uncaught SoapFault exception: [a:DeserializationFailed]
The formatter threw an exception while trying to deserialize the
message: Error in deserializing body of request message for operation
'Import'. End element 'Body' from namespace
'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element
'param1' from namespace ''. Line 2, position 162. in
Adrian -
From the snippets you gave, there is not much to determine about what you are trying to do. Without knowing the exact nature of the WSDL, it is hard to say what is going on - is Import a valid request, is it in the right format, etc.
I suggest loading your WSDL into SOAPUI and verifying that your XML format is correct. This is a very useful tool in preparing your SOAP requests before actually coding them in PHP.
http://www.soapui.org/
I would then suggest referencing the PHP manual for the SoapClient class to properly format your code.
http://php.net/manual/en/class.soapclient.php

Got parse error with Mail config headers in ZF2

I use Zend\Mail\Transport\Smtp to send an email. Below is my code.
use Zend\Mail\Message;
use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mail\Transport\SmtpOptions;
public function smtpConfig($message)
{
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'name' => localhost,
//'host' => 10.92.32.81,
'port' => 25,
));
$transport->setOptions($options);
echo $transport->send($message);
}
public function sendMail($to,$from,$subject,$body)
{
$message = new Message();
$message->addTo($to)
->addFrom($from)
->setSubject($subject)
->setBody($body);
$this->smtpConfig($message);
}
I have configured smtp in local system and I'm able to receive email without any warnings/low priority errors. I delivered this code for project testing. Mail functionality is working fine in their system but in browser console following warning/error is displayed and I dont see this error in my local setup.
Parse error: syntax error, unexpected '[' in D:\applications\www-php\kiosquebo\vendor\zendframework\zend-mail\src\Headers.php on line 39
Any solution given is appreciated.
According to the line in the file you're getting the error, PHP is failing to parse this line:
protected $headersKeys = [];
The only issue that is possible here is that your PHP version is too old and does not work with the [] array definer.
You should update your PHP version to at least 5.4.

Parse Error: Zend_Oauth::REQUEST_SCHEME_HEADER Error: Unexpected ',' while expecting '('

Using PHP GMail OAuth Library/Sample.
$options = array(
'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
'version' => '1.0',
'consumerKey' => $THREE_LEGGED_CONSUMER_KEY,
'callbackUrl' => getCurrentUrl(),
'requestTokenUrl' => 'https://www.google.com/accounts/OAuthGetRequestToken',
'userAuthorizationUrl' => 'https://www.google.com/accounts/OAuthAuthorizeToken',
'accessTokenUrl' => 'https://www.google.com/accounts/OAuthGetAccessToken'
);
Here's the error: Parse error: syntax error, unexpected ',', expecting '('
This is from line 77: the 'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER, line, any ideas?
Edit: I'm using PHP 4.4.8
You're using PHP 4, which does not support class constants; when it sees code like that, it's expecting a static function call, which it does support:
Class::static_function()
However, in the case of your code, the Zend_Oauth class has a const REQUEST_SCHEME_HEADER, a PHP 5-only feature, which is accessed like so:
Zend_Oauth::REQUEST_SCHEME_HEADER
This is why Zend Framework requires PHP 5. If you intend to use it, yes you'll need to contact your hosting provider to see if they offer PHP 5 as an option or something.
It looks like you are running PHP4.
Most likely your server has both php5 and php4 installed, but it defaults to php4. Contact your server provider.

Categories