I want to send batch emails with attachment. I can send the batch emails by attaching the same file to all the emails. But I need to attach different files to different emails by adding file path in recipient variables. I can't see anything related in the official documentation of mailgun.
Here is my code :
# Instantiate the client.
$mgClient = new Mailgun('key-****');
$domain = "foo.bar.com";
# Make the call to the client.
$result = $mgClient->sendMessage($domain, array(
'from' => 'gido#foo.baar.com',
'to' => array('user1#gmail.com', 'user2#gmail.com'),
'subject' => 'Hi %recipient.first%',
'text' => 'Hey there, Just Testing',
'recipient-variables' => '{"user1#gmail.com": {"first":"User1", "id":1, "file" : "/path/to/file1"},
"user2#gmail.com": {"first":"User2", "id": 2, "file" : "/path/to/file2"}}'
), array(
'attachment' => array('%recipient.file%')
));
The above code does not work. the attachment array is not able to use recipient variable. Replacing %recipient.image% with /path/to/file works fine.
As per conversation with the Mailgun support team, At this time Mailgun doesn't have a way to assign a specific attachment to each recipient. One thing that can be tried is serving the files on a server and assign the users a URL to retrieve the file from(This is suggested only in case if files are not confidential and stored permanently on the server.).
From the doc:
'attachment' => [['fileContent'=>$binaryFile,'filename'=>'test.jpg']]
OR
'attachment' => [['filePath'=>'/tmp/foo.jpg','filename'=>'test.jpg']]
OR (inline):
'inline' => [['filePath'=>'/tmp/foo.jpg', 'filename'=>'test.jpg']]
Related
I'm using the PHP SDK to integrate DocuSign eSign REST API into a Laravel application.
We have been asked to attach a couple of PDF files to every signature request email, but I don't know if this is even possible.
I thought that the EnvelopeAttachments resource would be a way to go, but signers do not receive any attachment so far and here it is said that such attachments are not visible for them.
Here there is the SDK code I am using:
$attachments = [
new Attachment([
'access_control' => 'sender',
'attachment_id' => '1',
'attachment_type' => '.pdf',
'data' => base64_encode($this->getPdf($document, $signers)),
'label' => 'attachment 1',
'name' => 'attachment 1',
'remote_url' => 'attachment 1',
]),
];
$envelope_definition = new EnvelopeDefinition([
'composite_templates' => $composite_templates,
'email_subject' => "Firmar $documentTypeSp",
// 'email_blurb' => "Se solicita su firma para el contrato $document->name",
'status' => "sent",
'attachments' => $attachments,
]);
$envelope_definition->setEnvelopeAttachments($attachments);
return $envelope_definition;
You cannot attach a file to this email that is auto-generated by the system.
The envelope attachment shows in the envelope, it is not attached to the email.
While I don't recommend it, your only option is to send emails yourself, with links going to your own webserver, where you generate embedded signing URLs on the fly and redirect the users.
I would suggest you consider an alternative to having the attachment in the email. Like having a link in the email that goes to some sort of cloud storage or to your own server.
The EnvelopeAttachments resource is used to attach a document to an envelope. According to the API documentation, attachments are not visible to signers. So, it appears that it is not possible to attach a file to the signature request email.
One alternative approach to include the PDF files in the email body is to embed them as inline images. You can convert the PDF to an image format, such as PNG or JPG, and then embed the image into the HTML email body using the <img> tag. The recipient can then view the PDF document directly in the email.
There is such a code, but it sends a single message to all the tokens specified in the array (1000 tokens). You need to add a personal parameter for each token somewhere to track the unique click - from whom it comes and so on. For example, in click_action. But again, if you add a parameter there, the link in this form will be sent to everyone. Sending one message for each user is not an option, of course.
'registration_ids' => $tokens,
'data' => array(
'title' => 'Title',
'body' => 'Message',
'icon' => 'icon.png',
'image' => 'image.png',
'click_action' => 'https://site.ru'
);
There is no (mail merge like) customization for each recipient within a single API call. Each call to the FCM API to send a message, sends precisely the message you pass in that call to the topics/tokens you target in that call.
If you want recipients to receive a different message, you will need to perform one API call for each message.
You say:
Sending one message for each user is not an option
Calling the API fo each unique message is precisely the only option. I'm not sure why it wouldn't be, as it's what all apps using FCM do if they want to deliver personalized content.
I am trying to send dynamic emails via the mailgun API in PHP but i'm not having any luck.
I can successfully send emails if i just send simple dynamic content. E.g.
$email = test#test.com;
$firstname = Tester;
$result = $mgClient->sendMessage($domain, array(
'from' => 'Support Team <hello#xyz.com>',
'to' => $email,
'subject' => 'Welcome to XYZ.com',
'html' => "<html>Dear $firstname, this is a test.</html>"
), array(
));
However i'd like to be able to pull content from a dynamic page E.g welcomeemail.php?userid=1. So i tried to use:
$html = file_get_contents(welcomeemail.php?userid=1
'html' => $html
However I get the following error "Warning: file_get_contents(welcomeemail.php?userid=1): failed to open stream: No such file or directory.
When I remove the ?userid=1, it works fine but obviously without the dynamic content.
Can you please provide any suggestions on how I can incorporate dynamic content into my emails?
You should put the full http path to welcomeemail.php. For an example file_get_contents('http://localhost/welcomeemail.php?userid=1'). When you don't put it like that the file_get_contents() looks for the file 'welcomeemail.php?userid=1' in the file system which is obviously doesn't exist.
I have an web application that is supposed to send emails with bounce controlling and analytics integration and i have an mail code like this:
Mail::send('emails.newsletter', [
'unsub_code' => $this->contact[$i][3],
'emailTo' => $this->contact[$i][1],
'emailFrom' => $this->email,
'user' => $this->contact[$i][0],
'UUID' => $this->contact[$i][2],
'campaignName' => $this->campaign->name,
'campaignId' => $this->campaign->id,
'header' => $header,
'body' => utf8_encode(html_entity_decode($this->campaign->body)),
'footer' => html_entity_decode($this->campaign->footer)],
function ($m) use ($i) {
$m->from('email#mydomain.ss', 'AAB');
$m->to($this->contact[$i][1])->subject($this->campaign->subject);
$headers = $m->getHeaders();
$headers->addPathHeader('Return-Path', 'bounce#mydomain.something');
$headers->addTextHeader('uuid', $this->contact[$i][2]);
$headers->addTextHeader('cpName', $this->campaign->name);
$headers->addTextHeader('cpId', $this->campaign->id);
});
My problem is that i want to send emails from other#otherdomain.xx but maintain the bounce#mydomain.ss but that gives me an error because the other#otherdomain isnt the same as the env one.
Well like jszobody pointed in the comments this is actually a problem with my hosting blocking me from sending email from other domains, this will actually be solved by purchasing another service from them which enables me to do so.
Since i'm developing the application i don't want to use a third-party SMTP provider which is also a good solution cost wise.
i´ve written a "pushserver" for my app via PHP.
The push notifications i´ve sent via PHP are all received on the device, so far.
But, i can just send/set the "message" and "title", see:
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array(
'message' => $message,
'title' => 'My App',
'vibrate' => 1,
'sound' => 1,
'icon' => "http://example.com/image.jpg",
"style" => "inbox"
),
);
"icon" and "style" are not working (vibrate and sound not tested, yet).
Every link for the parameters i´ve found is broken or kind of "you need to do object.setSomething() in JAVA.
Is there a list anywhere where i can see ALL parameters, which i can send to GCM? No matter, what language i use?
Cheers,
Chris
couple of things need to keep in mind while all the data which you sending from server end
Is there a list anywhere where i can see ALL parameters,
exp :- you can send as many parameters as you want but offcourse there is limitation but not key specific just like you can use "textmessage" instead of "message" but make sure to retrieve the value from same key which you are assigning from server end
1) please make sure that you are getting all the data in gcmintentservice class try to print the log of all intent data.
please remember that this is just a string data it is not going to download the image for you. you have to download using volley library or any suitable library