Here we'll show you how to use our PHP SDK to send an email via Gmail.
3You'll also need a Gmail account, which you can create here. To authenticate with Google, you'll want to enable 2-Step Verification and generate an App Password for Temboo.
4Sign in to your Google Account settings page by clicking on your name or picture in the upper right corner of the screen and then clicking Account.
5Scroll down to the "Signing in" box.
6Click 2-Step Verification. This will bring you to the 2-Step Verification settings page.
7You will then see a step-by-step guide which will guide you through the setup process.
8After you've enabled 2-Step Verification, you'll be prompted to create an App Password.
9In the Select app dropdown menu, choose "Other", and give this app a name (e.g., TembooApp).
10Click "Generate". You'll be given a 16-digit passcode that can be used to access your Google Account from Temboo.
Note: If you wish to authenticate with OAuth credentials, you should use the Google > Gmailv2 Choreos.
11 Go to the Google > Gmail > SendEmail Choreo in our Library.
12Fill in your Gmail username (email address) and App-specific password, then hit the Save Profile button to save a Profile for your Gmail account. Now you can reuse your Gmail authentication details on any of our Gmail Choreos and it will also make your PHP code simpler and more secure.
13On Google > Gmail > SendEmail Choreo page, Select PHP from the drop down menu at the top of the page. Insert your new Profile and fill in the rest of the required inputs.
14Click Generate Code to test the Choreo from our website, and you'll see the value "true" for the Success output in the Output section. Assuming you emailed yourself, you can go to your inbox and see the email appear!
15To send an email from your PHP code, copy the generated Code from your browser directly into your PHP script and try running it there. Remember to comment in the line that declares the
Temboo_Session object and substitute in your Temboo account details - you can find these on your Temboo Applications page. You'll also need to substitute in the name of the Gmail Profile you created earlier. Your code should look something like this:
<?php require 'php-sdk/src/temboo.php'; // Instantiate the Choreo, using a previously instantiated Temboo_Session object, eg: $session = new Temboo_Session("ACCOUNT_NAME", "APP_NAME", "APP_KEY"); $sendEmail = new Google_Gmail_SendEmail($session); // Get an input object for the Choreo $sendEmailInputs = $sendEmail->newInputs(); // Set Profile to use for execution $sendEmailInputs->setCredential('GmailProfile'); // Set inputs $sendEmailInputs->setMessageBody("Hello world!")->setSubject("Test from Temboo")->setFromAddress("email@example.com")->setToAddress("firstname.lastname@example.org"); // Execute Choreo and get results $sendEmailResults = $sendEmail->execute($sendEmailInputs)->getResults(); // Print status echo $sendEmailResults->getSuccess(); ?>
16Run the code and check your inbox - your email should be waiting.
We're all finished! Now your PHP application is sending email via your Gmail account. Why not check out the rest of the 2000+ Choreos in our Library and think about how you could extend this example by combining it with something else.
Once you've got your code up and running, you're ready to move on and do more. From monitoring your running applications, to moving your generated Temboo code to your preferred development environment and sharing it with colleagues, collaborators and friends - we've got you covered.
We're always happy to help. Just email us at email@example.com, and we'll answer your questions.