I am trying to trigger the send of a smart transactional email in Campaign Monitor from my Wordpress app
require_once( get_stylesheet_directory() . '/createsend-php-master/csrest_transactional_smartemail.php' );
# Authenticate with your API key
$auth = array('api_key' => 'apikey');
# The unique identifier for this smart email
$smart_email_id = 'emailid';
# Create a new mailer and define your message
$wrap = new CS_REST_Transactional_SmartEmail($smart_email_id, $auth);
$message = array(
"To" => 'email#email.com',
"Data" => array(
'x-apple-data-detectors' => 'x-apple-data-detectorsTestValue',
'href^="tel"' => 'href^="tel"TestValue',
'href^="sms"' => 'href^="sms"TestValue',
'owa' => 'owaTestValue',
),
);
# Send the message and save the response
$result = $wrap->send($message);
I've got the correct API and Email ID, and I'm using my gmail account to test with but the email just isn't getting triggered. I'm a beginner coder and I reckon I've just missed something completely obvious!
Path to the campaign monitor php file is correct too.
The API documentation is here https://www.campaignmonitor.com/api/transactional/?_ga=1.180877863.1694927084.1483423346 - is there anything I've missed out. Help is much appreciated!
Related
I am working on some code that will create an iCalendar and then send an Outlook email with an ics file of the created event, it works as intended but there is one problem.
When the email gets sent, the attachment is given the wrong name (ATT00001.bin instead of Meeting.ics) and it isn't sent as a .ics but as a .bin. The contents of the file are still just as they are supposed to be.
Any help is appreciated, thanks!
use Spatie\IcalendarGenerator\Components\Calendar;
use Spatie\IcalendarGenerator\Components\Event;
...
$calendar = Calendar::create('Company test meeting')
->event(Event::create()
->name('Company test meeting')
->description('A test meeting about Company')
->startsAt(new \DateTime('24-03-2022 10:00'))
->endsAt(new \DateTime('24-03-2022 11:30'))
)->get();
$mailer = new Mailer('default');
$mailer->setAttachments([
'Meeting.ics' => [
'data' => $calendar,
'contentDisposition' => false
]
]);
$mailer->setFrom(['replacement#outlook.com' => 'CompanyName'])
->setTo('replacement#outlook.com')
->setSubject('Company meeting')
->deliver('Hey there I would like to have a meeting about Company');
So I figured it out.
When I was making the email, I was using the cakephp 4 cookbook.
There it said that: "The mimetype and contentId are optional in this form." and I made the mistake of just assuming that I didn't need it.
The mimetype for a ics file is text/calendar so I just added this to my setAttachments like this:
$mailer = new Mailer('default');
$mailer->setAttachments([
'Meeting.ics' => [
'data' => $ical,
'mimetype' => 'text/calendar', //I added the mimetype here
'contentDisposition' => false
]
]);
$mailer->setFrom(['private#outlook.com' => 'Company'])
->setTo('private#outlook.com')
->setSubject('Companymeeting')
->deliver("Dummy text " . $attendee . " About " . $description . "");
$this->set('calendar', $ical);
I'm still working on how to get the right filename but that isn't as important as the file extension. But if anybody knows, I would love to know.
There is currently 25k+ users we have in database. All users are subscribed to a common topic All.
I have two directories inside public_html. First is for API built in codeigniter. This API is used to provide data for all adnroid and iOS devices.
Second directory is for admin panel built in Laravel. We use it to upload data and also to send notification to firebase topics.
Both API and Admin Panel share same database.
If we send notification to topics which is not subscribed by much
users, there is no issue. But If I send notificaiton to a topic
which has much users It causes problems on our backend. The API
stops responding, or sometimes takes too long to respond.
Sometimes also admin panel stops responding too.
I am so confused because all the things are handled by firebase. I just make one API call.
Can anyone explain what's causing the problem?
Or any possible reason?
Update
use Kreait\Firebase\Messaging;
use Illuminate/Support/Http/Request;
trait UserTrait {
public function notify(Request $request, Messaging $messaging) {
$message_hi = array(
"notification_type" => $notification_type,
"notification_title" => $notification_title_hi,
"icon_image" => $icon_image,
"notification_description" => $request->notificationText_hi,
"image_url" => $request->image_url,
);
$message = array(
"notification_type" => $notification_type,
"notification_title" => $notification_title,
"icon_image" => $icon_image,
"notification_description" => $request->notificationText,
"image_url" => $request->image_url,
);
$commodityIdArray = $request->cId
//to send all
if($request->notification_type == 1) {
$messaging->sendAll([
['topic' => 'All', 'data' => $message],
['topic' => 'All_hi', 'data' => $message_hi],
]);
} else {
//to send to a fourite topic subscribed by some users
//Prepare Condition for both hindi and english users
$topic_condition = "";
$topic_condition_hi = "";
foreach($commodityIdArray as $topic) {
$topic_condition .="'".$topic."' in topics && ";
$topic_condition_hi.="'".$topic."_hi' in topics &&";
}
//send notification to hindi and english topics
$messaging->sendAll([
['condition' => substr($topic_condition, 0, -3), 'data' =>
$message],
['condition' => substr($topic_condition_hi, 0, -3), 'data' =>
$message_hi],
]);
}
}
Use Queue
You have to use a Queue which set your process in queue and when one process completes, the second one starts
you can also set number of retries of your process
I am facing a problem when I try to send multiple images in a single MMS. Even their documentation is not clear.
I couldn't find an example online showing the same.
According to their documentation about MMS
Up to 10 images that together total no more than 5mb can be sent at one time.
MMS is also only available in the US and Canada.
You can pass the images by using an array like so.
URL method: (urls have to be publicly accessible)
<?php
// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once '/path/to/vendor/autoload.php';
use Twilio\Rest\Client;
// Find your Account Sid and Auth Token at twilio.com/console
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$twilio = new Client($sid, $token);
$mediaUrls = array("https://demo.twilio.com/owl.png", "url2", "url3", "url4");
$message = $twilio->messages
->create("+12316851234", // to
array(
"body" => "Hello there!",
"from" => "+15555555555",
"mediaUrl" => $mediaUrls
)
);
print($message->sid);
Documentation:
https://www.twilio.com/docs/sms/api/media-resource
https://www.twilio.com/docs/sms/send-messages?code-sample=code-send-an-mms-message&code-language=PHP&code-sdk-version=5.x
More information about this here https://www.twilio.com/docs/sms/tutorials/how-to-send-sms-messages-php
I would like to use a form to send a verification email though mailgun to users when they sign up for a service. I have a form collecting the required info for the email but need to put it into the email. The problem is the way the email is formatted and I do not know how to print the data.
Here is my action:
<?php
require 'vendor/autoload.php';
use Mailgun\Mailgun;
$mgClient = new Mailgun('MY-API-KEY');
$domain = "https://api.mailgun.net/v3/MY-DOMAIN";
$result = $mgClient->sendMessage($domain, array(
'from' => 'Verifier <MY-ADDRESS>',
'to' => '<?php print_r(GET_$[email]) ?>, second-address#email.com',
'subject' => 'Verifcation & Instructions',
'text' => 'Dear print_r(GET_$[username]),
Thank you for requesting a service for print_r(GET_$[url]).
To make sure this was you, please click here and verify ...'
));
?>
I know the send is working because of the second address I have set up.
Thanks for any help!
Here is a possible solution as given to me by Mailgun Support:
http://blog.mailgun.com/double-opt-in-with-php-mailgun/
I am trying to create tickets on my Zendesk and that is working fine. However i do not want Zendesk to email the creator of the tickets (his or her email). Is this possible?
The idea is i have a contactForm widget on my site, i want the submits from this form to create tickets in my Zendesk.
Creating tickets is currently working using this code:
$zendesk = new zendesk(
$row->api_key,
$row->email_address,
$row->host_address,
$suffix = '.json',
$test = false
);
$arr = array(
"z_subject"=>"Offline Message",
"z_description"=> $r->contact_msg,
"z_recipient"=>$r->contact_email,
"z_name"=>$r->contact_name,
);
$create = json_encode(
array('ticket' => array(
'subject' => $arr['z_subject'],
'description' => $arr['z_description'],
'requester' => array('name' => $arr['z_name'],
'email' => $arr['z_requester']
))),
JSON_FORCE_OBJECT
);
$data = $zendesk->call("/tickets", $create, "POST");
Any ideas?
Totally possible! You need to add some conditions to the trigger "Notify requester of received request" in Zendesk - Trigger setting to prevent zendesk from sending email. For ex:
Ticket : Channel - Is Not - Webservice (API)
Ticket : Tags - Contains one of the following - "offline message"
You could use another API endpoint "Ticket Import" https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_import/
It's do not send notifications