I'm sending a PDF file via CURL in Laravel:
<?php
namespace App\Http\Controllers\EmailSender;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class EmailAttachments extends Mailable{
use Queueable, SerializesModels;
function __construct($from, $to, $subject, $description, $attachments, $file_names = null){
if(str_contains($to, 'email.com')){
return;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, 'https://api.eu.mailgun.net/v3/'.config('app.mailgun_domain').'/messages');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: multipart/form-data'));
$post = array(
'from' => $from,
'to' => $to,
'subject' => $subject,
'text' => 'Your mail do not support HTML',
'html' => $description
);
// Attach all my files
// Note that this files are with the full path, since the public_path to the file
$i = 0;
foreach ($attachments as $attachment) {
echo $attachment;
$post['attachment[' . $i . ']'] = curl_file_create($attachment, null, $file_names == null ? 'Report_' . date('W') .'.pdf' : $file_names[$i]);
$i++;
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_USERPWD, 'api' . ':' . config('app.mailgun_secret'));
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
}
}
?>
And I'm getting this message:
libpng warning: iCCP: known incorrect sRGB profile
Error:operation aborted by callback
I am doing the same way in other project and its working.
I checked the files and the paths are ok. I double checked. The path is ok and the extension file is ".pdf".
Example:
/home/root/backend.app.com/storage/app\works\obras\Report_0.pdf
The file is created and ready to be attached. I searched for solutions but all the topics are talking about PNG and other formats. And I didn't find the solution.
I tried to update Curl but still no success.
echo $attachment;
? If so, is it possible that some command is generated a PDF but failing and returning an error message, and you are seeing it here?