I'm trying to send image into email,
My image code is: <?php echo $this->Html->image('image-name.jpg', ['class'=>'img-responsive']); ?>
While i'm debug email template in my localhost, it's working fine, image displaying properly, but when this same code make it live on server and fire email, email content display properly but image not showing(not found).
Any body will suggest proper way to implement it.
Thanks,
Mak
For the email or in whole website if you want to full path of content use fullBase param with true value,
echo $this->Html->image("logo.png", ['fullBase' => true]);
Will output:
<img src="http://example.com/img/logo.jpg" alt="" />
https://book.cakephp.org/3.0/en/views/helpers/html.html#linking-to-images
This is a proper way that suggested by CakePhp framework.
First attach the file what you want to send
$email->attachments([
'photo.png' => [
'file' => '/full/some_hash.png',
'mimetype' => 'image/png',
'contentId' => 'unique-id'
]
]);
And then in your email template, add the unique id
<img src="cid:unique-id">
Detail explanation, here
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.
I'd like to create a message in the #general channel of my Slackspace from within a PHP script. The message should contain text and an image which was created locally on-the-fly.
I've already created an App, generated an bearer token and have managed to create an text-only message also as an image-upload.
But i didn't know how to create both in one message, as the procedure above creates two messages, one with text and another one with the image.
There are two different approaches on how to post a Slack message with an image.
A. Upload image directly with message
You can upload an image directly to Slack and share it in a channel. Within that request you can also add a comment that will appear as message above the images. This is the easiest approach, however you comment is limited to one string.
API method: files.upload with these arguments:
channels: ID of one or multiple channel for the image to appear in
initial_comment: Your message
B. Post message with image block / attachment
Alternatively you can add an image to your normal message either as image block or secondary attachment. This only works with a public URL to your image file, so you first need to upload your image to an image hoster (which can be your Slack workspace) to get the public URL.
In our example we will use Slack as image hoster, but you can use any image hoster (e.g. Imgur) even your own webserver, as long as you get a public URL for your image file.
Step 1 - Upload image to Slack
API method: files.upload with no special arguments, but make sure to get the file ID from the response. Don't include the channels argument or the image will be posted visible into those channel.
Step 2 - Create public URL
Next you have to mark the uploaded file as public. Only then will it be accessible through its public_url property
API method: files.sharedPublicURL with the file ID as argument.
Next you need to construct the direct image link from the link to website / permalink_public property of the file.
The website link you get from permalink_public has the format:
https://slack-files.com/{team_id}-{file_id}-{pub_secret}
The direct link to the image has the format:
https://files.slack.com/files-pri/{team_id}-{file_id}/{filename}?pub_secret={pub_secret}
So you just need to extract the pub_secret from permalink_public and you should be able to construct the direct link to the image. The other parameters you can get from your file object.
Step 3 - Send message
Finally compose your message with the image URL either as Image Block or in a secondary attachment and submit it using a method of your choice.
API method: chat.PostMessage or any other method for sending message incl. incoming webhooks.
Answer to OP
If you need to stick with webhooks as it appears from your comments and have no access to the Slack API I would suggest uploading the image to an image hoster (e.g. Imgur) and then use approach B.
See also
Slack bot send an image
Can I upload an image as attachment with Slack API?
How to use the permalink_public URL of an uploaded image to include it in a message?
After much tinkering I found that while I could not use the API to create a message and upload an image simultaneously, I can first upload an image and then, with the timestamp returned, use update message to add text to the original message with the image upload.
This is the flow:
1- Use files_upload method to upload an image to my channel (using the channel name)
response = client.files_upload(
channels=my_channel_name,
file=image_path,
initial_comment='My initial comment'
)
2- Get the response from the files_upload and extract the channel id and timestamp of the message.
channel_id = response['file']['groups'][0]
ts = response['file']['shares']['private'][channel_id][0]['ts']
3- Use chat update to add text or rich content to the message with the uploaded image:
response = client.chat_update(
channel=channel_id,
text="My Message",
ts=ts,
blocks=blocks_list
)
For those who might still need this.. this gist helped me. Its a quick and easier way using GuzzleHttp.
use GuzzleHttp\Client;
/**
* Notes:
*
* Tested with guzzlehttp/guzzle version 7.3
* See https://api.slack.com/methods/files.upload for details on how to generate a token
*
*/
$fileName = '';
$filePath = '';
$slacktoken = ''; // See https://api.slack.com/tokens; The token will need file.read and file.write permissions
$client = new Client();
$apiUrl = 'https://slack.com/api/files.upload';
$client = new Client();
$request = $client->post( $apiUrl, [
'headers' => ['Authorization' => 'auth_trusted_header'],
'multipart' => [
[
'name' => 'token',
'contents' => $slacktoken,
],
[
'name' => 'file',
'contents' => fopen($filePath, 'r'),
'filename' => $fileName
],
[
'name' => 'channels',
'contents' => '#general'
],
[
'name' => 'initial_comment',
'contents' => 'File Uploaded'
]
]
]);
var_dump($request->getBody()->getContents());
If I were to paste this URL in the browser, the API indeed returns an image:
https://maps.googleapis.com/maps/api/place/photo?
maxwidth=400&photoreference=examplereference&key=examplekey
Keep in mind I have removed photoreference because it is too long and the secret key because it should be private.
After getting the image using PHP, I can't seem to send anything I can work with to my front end.
$getImage = file_get_contents("https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=examplereference&key=examplekey");
$image = json_decode($getImage);
return response()->json([
'message' => 'Fetched sight!',
'image' => $image
], 201);
If I try to send $image to the front-end it returns NULL and if I try to send $getImages, I get an error "Malformed UTF-8 characters, possibly incorrectly encoded".
Even after reading the documentation - https://developers.google.com/places/web-service/photos , I can't figure out what am I expected to receive from that request.
If you want to give an image content with a JSON API endpoint, you can base64 it's content.
<?php
$getImage = file_get_contents("https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=examplereference&key=examplekey");
$image = base64_encode($getImage);
return response()->json([
'message' => 'Fetched sight!',
'image' => $image
], 201);
On client side you can create image like this :
<img src="data:image/png;base64, <image content here>" />
Beware the client will perform some extra operations to create the image (not optimized for large image content).
Another solution could be to download the image with your backend and serve it with a classic URL from your server.
Hi I'm trying to use Mailchimp library with mailchimp php sdk. I'm trying to change the HTML content with api call using this.
$MailChimp = new \DrewM\MailChimp\MailChimp('api key');
$MailChimp->verify_ssl = false;
$MailChimp->patch('templates/temp id', [
'name' => 'my template',
'html' => '<p>dsd</p>'
]);
if ($MailChimp->success()) {
print_r($result);
} else {
echo $MailChimp->getLastError();
}
since we can change the name without any issue it seems like the issue relies on 'html' => '<p>dsd</p>'. It would be great help if someone can check.
error message I got is,
400: The resource submitted could not be validated. For field-specific
details, see the 'errors' array.
This error happens when an API request attempts to change a template that doesn't allow custom HTML. On the templates page in MailChimp, any template that's labeled as 'Drag and drop' will fail to update the HTML with an API request. It needs to be labeled as 'Code your own'.
The format can't change once it's set, so you'll have to create a new template and choose 'Code your own' on the creation page, then it will allow the html request parameter to be updated using the API.
Also, if you need to use the same design from your old template, you can export it as HTML, but the drag and drop features won't work when you import it to the new template.
Hope this helps!
I want to send an image and icon in my Push notification from my Serverside(php) to my app.
I have searched on Google but was unable to get the proper result.
I get FCM PHP Code. I use these code for sending notification but when I use "image and icon" parameter image not receive in notification.
In GCM it's easy to send icon and image in Push notification
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array(
"title" => "SamplePush Application",
"style" => "inbox"; //picture/inbox,
"message" => "I am just testing Push notification",
"notId" => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"summaryText" => "Venha provar os nossos Gins",
"image" => "http://gintonico.com/content/uploads/2015/03/fontenova.jpg",
"picture" => "http://media5.letsbonus.com/products/285000/285006/14014409744462-0-1700x690.jpg"
) ,
If anyone can send image and icon in notification using FCM please help me.
Simply, I change my plugin and use phonegap-plugin-push v2.0.x and it work fine. Now I am able to send big image in the notification.
Notification image must be PNG image. Replace jpg image with png image.