I am trying to use the mailjet send API for transactional emails from my wordpress website. My mailjet account works fine and I have a contact form that works fine with the mailjet plugin. When the contact form is submitted, an email is sent using mailjet.
Now I want to use the transactional templates from mailjet to replace my actual wp_mail function used in my contact page, because the emails sent using wp_mail doesn't look nice.
I already uploaded the php library (no composer) https://github.com/mailjet/mailjet-apiv3-php-no-composer to my server to the path htdocs/. I created a template on mailjet and published it. The template has the id mentioned in the code below.
This is my code for the send api transactional contact emails.
<form action="" name="contactform" method="post">
...
</form>
<?php
if($emailisright=="OK"){
require_once("/mailjet-apiv3-php-no-composer-master/vendor/autoload.php");
use \src\Mailjet\Resources;
$apikey = '***********************';
$apisecret = '***************************';
$body = [
'Messages' => [
[
'From' => [
'Email' => "no_reply#myemail.com",
'Name' => "Contact mywebsite"
],
'To' => [
[
'Email' => "testemail#gmail.com",
'Name' => "Test email"
]
],
'TemplateID' => 4546355,
'TemplateLanguage' => true,
'Subject' => "Re : contact",
'Variables' => json_decode('{
"name": "Tester",
"mailcc": "testemail#gmail.com",
"message": "test 9"
}', true)
]
]
];
$response = $mj->post(Resources::$Email, ['body' => $body]);
$response->success() && var_dump($response->getData());
}
?>
The page got blank. But when I exclude the following line code //use \src\Mailjet\Resources; then the page renders perfectly, but when submitting the form, I get a broken page which is normal as the line code //use \src\Mailjet\Resources; has been removed. This means that use \src\Mailjet\Resources; seems to be the issue. I also tried with use \Mailjet\Resources; but same broken result.
Now I am not sure I uploaded the php library on the right place on my server. This is the full server path to the wordpress website /opt/bitnami/apps/wordpress/htdocs.
Where do I have to upload the PHP mailjet library?
And where do I have to upload my contact page? On the same level of the mailjet PHP library?
Related
devs,
so I have been struggling with this problem for about 10 hours now, and I can't seem to find a solution online, worst is that I don't even know why it happens.
I am working on a project which uses PHP LARAVEL as the backend and I started writing the API for the flutter frontend to consume then I ran into this error while trying to test the API endpoint for registering and logging in.
The problem is the process fails with this error when I try to generate or create a token for the registered user or logged-in user.
Here a snapshot of my register function
public function store(Request $request)
{
$validated = Validator::make($request->all(),[
"email" => "required|email",
"password" => 'required',
"first_name"=> "required",
"last_name" => "required",
"phone_number" => 'required',
]);
if ($validated->fails()) {
return response()->json(['errors' => "Invalide credentials"], 403);
}
$user = User::create(
// [
// 'first_name' => $request->first_name,
// 'last_name'=> $request->last_name,
// 'email' => $request->email,
// 'password' => bcrypt($request->password),
// 'phone_number' => $request->phone_number,
// ]
$request->toArray()
);
Auth::guard('api')->check($user);
// $newUser = User::find($user->id);
$token = $user->createToken('authToken')->accessToken;
// return $token;
return response(['token' => $token, 'first_name'=>$user->first_name, 'email'=>$user->email ], 200);
}
The login and register functions all look the same at this point.
Error-causing code is :
$token = $user->createToken('authToken')->accessToken;
Please I am open to your suggestions, thanks.
I finally found a solution for this error and I believe it will help anyone out there with a similar problem.
The problem originates from the fact that your application is unable to asign a unique id to your client, remember your website or mobile app is a client to the backend with also(your mobile app or website) might have other users, so laravel passport will need to identify it with a unique id, below are some of the steps i used to fix this error.
First it originates because during the passport installation, i forgot to install
Blockquote
--uuids
If you have a similar error, follow the steps below to fix:
NOTE: You must have laravel passport installed already, if not, them follow the complete installtion guide Here
Step 1:
Install passport uuids
php artisan passport:install --uuids
Your result will look something like
After creating, the uuid for your application, you will have to include it in your .env file as such:
PASSPORT_PERSONAL_ACCESS_CLIENT_ID=986eb40c-0458-4b6e-bead-ea2fc4987033
PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET=VXLdTpqWK9i3CBqFwZgje5fuerQ5Uf2lvwXJqBoP
And there you go, you can now try to do what you couldn't do before.
I'm using the Hubspot API to create new contacts and would like to automatically set the owner when the contact is created. I know this is possible without using the API via Workflows, however I'd like to use the API for that.
Here's my code right now (which works, just missing the contact owner):
$data = [
'properties' => [
['property' => 'firstname', 'value' => $contact->first_name],
['property' => 'lastname', 'value' => $contact->last_name],
]
];
$body = json_encode($data);
$response = $client->request('POST', '/contacts/v1/contact/email/'.$user->email.'/profile',
['query' => ['hapikey' => $hubspot_key, 'body' => $body]);
I eventually found a way to achieve this:
Go to your Hubspot instance, then Settings and Properties
Search for "Contact Owner" and click on Edit
In "Field type", identify the Owner's ID value
Then in your API call, simply pass this property:
$data['properties'][] = ['property' => 'hubspot_owner_id', 'value' => 123456];
You can find out more about the hubspot_owner_id property (which is internal to Hubspot, this is not a custom property) in Hubspot's documentation.
It will automatically assign the newly created (or updated) Hubspot contact to the related Owner (Hubspot User).
I am working on Twitter API to create a functionality for the users to tweet directly from the software:
Here is my code:
$connection = new TwitterOAuth($this->getTwitterbpTable()->getConsumerKey(), $this->getTwitterbpTable()->getConsumerSecret(), $account->oauth_token , $account->oauth_secret);
$connection->setTimeouts(10, 150);
$media1 = $connection->upload('media/upload', ['media' => 'https://bleupagereview.files.wordpress.com/2014/02/bleupage.png']);
$parameters = [
'status' => 'My Media tweet here',
'media_ids' => implode(',', [$media1->media_id_string])
];
$connection->post('statuses/update', array('status' => $parameters));
The scripts works fine (does not throw any error/exception), but instead of uploading the file, it simply tweets the media id.
How should I change it so that it uploads the media file with status message.
Post function should be like this:
$connection->post('statuses/update', $parameters);
I'm using the oneAuth bundle in laravel, based on NinjAuth from Fuel by Phil Sturgeon, I believe, and trying to get the user's email address.
I've added the proper scope to my request, and the LinkedIn auth screen successfully asks for the users permission for basic profile AND email address.. so far, so good..
A possible issue is: what is the proper name of the email field?
I've found references to email-address, emailAddress, 'emailaddress`...
The docs indicate email-address, but its not working for me :)
I'm using the URL: https://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,member-url-resources,picture-url,location,public-profile-url,email-address)?format=json
This is the problematic snippet from /bundles/oneauth/libraries/oauth/provider/linkedin.php
// Create a response from the request
return array(
'uid' => array_get($user, 'id'),
// 'email' => array_get($user, 'email-address)',
// 'email' => array_get($user, 'emailAddress)',
'name' => array_get($user, 'firstName').' '.array_get($user, 'lastName'),
'image' => array_get($user, 'pictureUrl'),
'nickname' => $nickname,
'description' => array_get($user, 'headline'),
'location' => array_get($user, 'location.name'),
'urls' => array(
'linkedin' => $linked_url,
),
);
If I uncomment the email field, the request fails somehow (URL still shows mysite.com/connect/callback but the favicon shows linkedin and i get ablank page in chrome: "Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.")
If the email line in the code above IS commented out, I successfully receive all the other details and a new record is added to my users table and the table oneauth_clients, but email is naturally blank..
I must be missing something simple!
Update
The request URL works with email-address, but returns a json object containing emailAddress!!
The script still dies if the return array code above includes emailAddress...
Here is someone's success story:
"I made these two changes to the library and the demo.php respectively:
const _URL_REQUEST = 'https://api.linkedin.com/uas/oauth/requestToken?scope=r_basicprofile+r_emailaddress';
$response = $OBJ_linkedin->profile('~:(id,first-name,last-name,picture-url,email-address)');
The issue was that the Request Token Call is:
https://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,member-url-resources,picture-url,location,public-profile-url,email-address)?format=json
but the json response is:
array(8) {
["emailAddress"]=>
string(18) "email#email.com"
["firstName"]=>
string(3) "Tim"
...
Note that in the first case email is named email-address, in the second emailAddress.
The secondary problem was a shortcoming of my code - now working perfectly!
I can successfully get the contacts from google using OAuth gem in rails. my gmail configuration is :
:google=>{
:key=>"***",
:secret=>"***",
:expose => true,
:scope=>"https://www.google.com/m8/feeds/"
}
now i want to get contact from yahoo and hot mail. How to get that contact I have given following configuration in my oauth_consumer.rb file
:yahoo=>{
:client=>:oauth_gem,
:expose => true,
:allow_login => true,
:key=>"**",
:secret=>"**",
:scope=>"https://me.yahoo.com"
}
:hotmail=>{
:client=>:oauth_gem,
:expose => true,
:allow_login => true,
:key=>"**",
:secret=>"**"
}
when i am trying to do same like what is done in google it gives error like undefined methoddowncase' for nil:NilClass`
I have also tried contacts gem but fail to load contacts.
Please try to use OmniContacts https://github.com/Diego81/omnicontacts this will help you alot.
In your gemfile
gem "omnicontacts"
Create config/initializers/omnicontacts.rb
require "omnicontacts"
Rails.application.middleware.use OmniContacts::Builder do
importer :gmail, "client_id", "client_secret", {:redirect_path => "/oauth2callback", :ssl_ca_file => "/etc/ssl/certs/curl-ca-bundle.crt"}
importer :yahoo, "consumer_id", "consumer_secret", {:callback_path => '/callback'}
importer :hotmail, "client_id", "client_secret"
importer :facebook, "client_id", "client_secret"
end
Create an app to yahoo https://developer.apps.yahoo.com/projects
This will ask to verify your domain. So, just change your domain of localhost:3000 to local.appname.com:3000 or prefer your live server... (change host in local --- sudo gedit /etc/hosts)
in your controller
#contacts = request.env['omnicontacts.contacts']
#user = request.env['omnicontacts.user']
puts "List of contacts of #{user[:name]} obtained from #{params[:importer]}:"
#contacts.each do |contact|
puts "Contact found: name => #{contact[:name]}, email => #{contact[:email]}"
end