Skip to content
Advertisement

Sendinblue attachment

I try to send attachment pdf file. I get the email but no attachmetn. I have try to use https://github.com/sendinblue/APIv3-php-library/blob/master/docs/Model/SendSmtpEmail.mdenter

 $sendSmtpEmail = new SendinBlueClientModelSendSmtpEmail(); 
    $sendSmtpEmail['to'] = array(array('email'=>'email@email.com'));
    $sendSmtpEmail['templateId'] = 39;
    $sendSmtpEmail['params'] = array(
    'NUMEROFACTURE'=> "12345",
    'CODECLIENT' => "1234567",
    'TOSEND' => "email1@email.net",
    'MONTANTFACTURE'=>  number_format(12, 2, ',', ' '),
    );
    $attachement = new SendinBlueClientModelSendSmtpEmailAttachment();
    $attachement['url']= __DIR__'/facture/Facture-'.$row["ClePiece"].'.pdf';
    $attachement['name']= 'Facture-'.$row["ClePiece"].'.pdf';
    $attachement['content']= "utf-8";
    $sendSmtpEmail['attachment']= $attachement;
    $sendSmtpEmail['headers'] = array('Content-Type'=>'application/pdf','Content-Disposition'=>'attachment','filename'=>'Facture-'.$row["ClePiece"].'.pdf',"charset"=>"utf-8");


$config = SendinBlueClientConfiguration::getDefaultConfiguration()->setApiKey('api-key', 'YOUR_API_KEY');
$apiInstance = new SendinBlueClientApiSMTPApi(new GuzzleHttpClient(),$config);

try {
    $result = $apiInstance->sendTransacEmail($sendSmtpEmail);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling SMTPApi->sendTransacEmail: ', $e->getMessage(), PHP_EOL;
}

Advertisement

Answer

    $dataEmail= new SendinBlueClientModelSendEmail();
    $dataEmail['emailTo']       = ['abc@example.com', 'asd@example.com'];
    $dataEmail['attachmentUrl'] = "http://www.ac-grenoble.fr/ia07/spip/IMG/pdf/tutoriel_pdf_creator-2.pdf";

    // if you want to use content attachment base64 
    // $b64Doc = chunk_split(base64_encode($data));
    // $attachment_array = array(array(
    //                              'content'=>$b64Doc,
    //                              'name'=>'Facture-'.$row["ClePiece"].'.pdf'
    //                          ));
    //  $dataEmail['attachment']    = $attachment_array;
    //Don't forget to delete attachmentUrl

    $templateId = 39;
    $dataEmail  = $dataEmail;

    $config = SendinBlueClientConfiguration::getDefaultConfiguration()->setApiKey('api-key', 'YOUR_API_KEY');

    $apiInstance = new SendinBlueClientApiSMTPApi(new GuzzleHttpClient(),$config);
    try {
        $result = $apiInstance->sendTemplate($templateId, $dataEmail);
        print_r($result);
    } catch (Exception $e) {
        echo 'Exception when calling SMTPApi->sendTemplate: ', $e->getMessage(), PHP_EOL;
    }
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement