We send emails through SendGrid with the help of the sendgrid-php library. This works like a charm.
Since recently we noticed that if a filename has already been placed as a attachment, only one of both gets send to the receiver.
Have two files with the exact same name but in different folders.
Try to send them as attachment to a random emailaddress
Thanks for reporting this @biggienor,
We have added this to our backlog for a fix.
Hi,
I tried this using the code in this Gist:
https://gist.github.com/joe-niland/e69c223b85a481b30ca2548c85c7b4e2
Seemed to work fine - I received two attachments, both with the same file name. @biggienor is this how you were using the SDK?
Hi @joe-niland,
Thanks for providing the feedback. We don't add attachment as followed:
$att1 = new \SendGrid\Attachment();
$att1->setContent( file_get_contents("test_files/1/1.txt") );
$att1->setType("text/plain");
$att1->setFilename("1.txt");
$att1->setDisposition("attachment");
$mail->addAttachment( $att1 );
We add the file directly into the addAttachment() function. Is it necessary to use the other functions as well?
Hey @biggienor
I'm not familiar enough with the internals to comment, sorry.
If you have a code snippet, I could try to repro your issue.
@biggienor,
If you are uncomfortable sharing the code publicly, please send to [email protected]. Thanks!
@thinkingserious thinkingserious
Sorry for the late response. I wasn't aware that I did not get notified for replies.
I think i've found the bug in my case.
In the toWebFormat() function of the Email library, the following code is writen.
`if ($this->getAttachments()) {
foreach ($this->getAttachments() as $f) {
$file = $f['file'];
$extension = null;
if (array_key_exists('extension', $f)) {
$extension = $f['extension'];
};
$filename = $f['filename'];
$full_filename = $filename;
if (isset($extension)) {
$full_filename = $filename . '.' . $extension;
}
if (array_key_exists('custom_filename', $f)) {
$full_filename = $f['custom_filename'];
}
if (array_key_exists('cid', $f)) {
$web['content[' . $full_filename . ']'] = $f['cid'];
}
$contents = '@' . $file;
// Guzzle handles this for us.
// http://guzzle3.readthedocs.org/en/latest/http-client/request.html#post-requests
// if (class_exists('CurlFile', false)) { // php >= 5.5
// $contents = new \CurlFile($file, $extension, $filename);
// }
$web['files[' . $full_filename . ']'] = $contents;
};
}`
Our clients demand that the exact filename should be represented in the attachments. We use the custom_filename option for this matter, which would result that the key in $web will be overwritten.
Thanks for following up @biggienor and to @joe-niland for lending a hand.
If you both of you would kindly fill out this form, I would love to send you some swag.
Thanks @thinkingserious - very kind!
Thanks @thinkingserious 馃憤
Hi @thinkingserious
Is this bug already resolved in a version of sengrid-php? I would love to hear from you!
Hello @biggienor,
I believe that we determined there was no bug. Are you still having issues?
HI @thinkingserious,
The code I showed above is coming from your API. Can you help me by telling me if I have to update the API? Our current version is 4.0.4 and the code here is 5.1.2?
Hi @biggienor,
If you want to use @joe-niland's solution, then yes, please update to the latest version of this library.