Attach invoice pdf attachment to custom e-mail in magento 2












0















I created a custom email and it's working fine like this:



    $data['amount'] = round($amount);
$data['customer_name'] = $customer->getFirstname() . ' ' . $customer->getLastname();
$data['customer_telephone'] = $customer->getMainTelephone();
$data['customer_email'] = $customer->getEmail();
$data['customer_credit_balance'] = round($creditBalance);
$data['requested_at'] = $model->getRequestedAt();
$data['customer_bank_account'] = $description;
$storeName = $this->getStoreName();
$storeEmail = $this->getStoreEmail();
$senderInfo = [
'name' => $storeName,
'email' => $storeEmail
];
$receiverInfo = [
'name' => $data['customer_name'],
'email' => $data['customer_email']
];
$this->emailHelper->sendMail(
$data,
$senderInfo,
$receiverInfo,
'approve'
);


//emailHelper
public function sendMail($emailTemplateVariables,$senderInfo,$receiverInfo,$type)
{
if ($type == 'request') {
$typeId = self::XML_PATH_EMAIL_TEMPLATE_FIELD_REQUEST;
} elseif ($type == 'approve') {
$typeId = self::XML_PATH_EMAIL_TEMPLATE_FIELD_APPROVE;
} else{
$typeId = self::XML_PATH_EMAIL_TEMPLATE_FIELD_REJECT;
}
$this->temp_id = $this->getTemplateId($typeId);
$this->inlineTranslation->suspend();
$this->generateTemplate($emailTemplateVariables,$senderInfo,$receiverInfo);
$transport = $this->_transportBuilder->getTransport();
$transport->sendMessage();
$this->inlineTranslation->resume();
}


template:



 <!--@subject Your Request is Approved @-->
<!--@vars
{"htmlescape var=$name":"Recipient Name",
"htmlescape var=$sendername":"Sender name",
"var code":"Gift Card Code",
"var balance":"Gift Card Balance",
"var status":"Status",
"htmlescape var=$message":"Message",
"var expiredat":"Expired At"}
@-->

<!--@styles
body,td { background:#FFFFFF; margin:0; padding:0; color:#2f2f2f; font:13px/1.35em Verdana, Arial, Helvetica, sans-serif; }
pre{ white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;}
@-->
{{template config_path="design/email/header_template"}}
<div style="font:13px/1.35em Verdana, Arial, Helvetica, sans-serif;">
<table cellspacing="0" cellpadding="0" border="0" width="98%"
style="margin-top:10px; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; margin-bottom:10px;">
<tr>
<td align="center" valign="top">
<!-- [ middle starts here] -->
<table cellspacing="0" cellpadding="0" border="0" width="660">
<tr>
<td valign="top">
<p>
<strong>Dear {{var customer_name}},</strong>,<br/>
Your request to process {{var amount}} has been approved and processed.</br>
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>


if i have invoice id as a variable, how can i attach my pdf invoice to this email?









share



























    0















    I created a custom email and it's working fine like this:



        $data['amount'] = round($amount);
    $data['customer_name'] = $customer->getFirstname() . ' ' . $customer->getLastname();
    $data['customer_telephone'] = $customer->getMainTelephone();
    $data['customer_email'] = $customer->getEmail();
    $data['customer_credit_balance'] = round($creditBalance);
    $data['requested_at'] = $model->getRequestedAt();
    $data['customer_bank_account'] = $description;
    $storeName = $this->getStoreName();
    $storeEmail = $this->getStoreEmail();
    $senderInfo = [
    'name' => $storeName,
    'email' => $storeEmail
    ];
    $receiverInfo = [
    'name' => $data['customer_name'],
    'email' => $data['customer_email']
    ];
    $this->emailHelper->sendMail(
    $data,
    $senderInfo,
    $receiverInfo,
    'approve'
    );


    //emailHelper
    public function sendMail($emailTemplateVariables,$senderInfo,$receiverInfo,$type)
    {
    if ($type == 'request') {
    $typeId = self::XML_PATH_EMAIL_TEMPLATE_FIELD_REQUEST;
    } elseif ($type == 'approve') {
    $typeId = self::XML_PATH_EMAIL_TEMPLATE_FIELD_APPROVE;
    } else{
    $typeId = self::XML_PATH_EMAIL_TEMPLATE_FIELD_REJECT;
    }
    $this->temp_id = $this->getTemplateId($typeId);
    $this->inlineTranslation->suspend();
    $this->generateTemplate($emailTemplateVariables,$senderInfo,$receiverInfo);
    $transport = $this->_transportBuilder->getTransport();
    $transport->sendMessage();
    $this->inlineTranslation->resume();
    }


    template:



     <!--@subject Your Request is Approved @-->
    <!--@vars
    {"htmlescape var=$name":"Recipient Name",
    "htmlescape var=$sendername":"Sender name",
    "var code":"Gift Card Code",
    "var balance":"Gift Card Balance",
    "var status":"Status",
    "htmlescape var=$message":"Message",
    "var expiredat":"Expired At"}
    @-->

    <!--@styles
    body,td { background:#FFFFFF; margin:0; padding:0; color:#2f2f2f; font:13px/1.35em Verdana, Arial, Helvetica, sans-serif; }
    pre{ white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;}
    @-->
    {{template config_path="design/email/header_template"}}
    <div style="font:13px/1.35em Verdana, Arial, Helvetica, sans-serif;">
    <table cellspacing="0" cellpadding="0" border="0" width="98%"
    style="margin-top:10px; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; margin-bottom:10px;">
    <tr>
    <td align="center" valign="top">
    <!-- [ middle starts here] -->
    <table cellspacing="0" cellpadding="0" border="0" width="660">
    <tr>
    <td valign="top">
    <p>
    <strong>Dear {{var customer_name}},</strong>,<br/>
    Your request to process {{var amount}} has been approved and processed.</br>
    </p>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </div>


    if i have invoice id as a variable, how can i attach my pdf invoice to this email?









    share

























      0












      0








      0








      I created a custom email and it's working fine like this:



          $data['amount'] = round($amount);
      $data['customer_name'] = $customer->getFirstname() . ' ' . $customer->getLastname();
      $data['customer_telephone'] = $customer->getMainTelephone();
      $data['customer_email'] = $customer->getEmail();
      $data['customer_credit_balance'] = round($creditBalance);
      $data['requested_at'] = $model->getRequestedAt();
      $data['customer_bank_account'] = $description;
      $storeName = $this->getStoreName();
      $storeEmail = $this->getStoreEmail();
      $senderInfo = [
      'name' => $storeName,
      'email' => $storeEmail
      ];
      $receiverInfo = [
      'name' => $data['customer_name'],
      'email' => $data['customer_email']
      ];
      $this->emailHelper->sendMail(
      $data,
      $senderInfo,
      $receiverInfo,
      'approve'
      );


      //emailHelper
      public function sendMail($emailTemplateVariables,$senderInfo,$receiverInfo,$type)
      {
      if ($type == 'request') {
      $typeId = self::XML_PATH_EMAIL_TEMPLATE_FIELD_REQUEST;
      } elseif ($type == 'approve') {
      $typeId = self::XML_PATH_EMAIL_TEMPLATE_FIELD_APPROVE;
      } else{
      $typeId = self::XML_PATH_EMAIL_TEMPLATE_FIELD_REJECT;
      }
      $this->temp_id = $this->getTemplateId($typeId);
      $this->inlineTranslation->suspend();
      $this->generateTemplate($emailTemplateVariables,$senderInfo,$receiverInfo);
      $transport = $this->_transportBuilder->getTransport();
      $transport->sendMessage();
      $this->inlineTranslation->resume();
      }


      template:



       <!--@subject Your Request is Approved @-->
      <!--@vars
      {"htmlescape var=$name":"Recipient Name",
      "htmlescape var=$sendername":"Sender name",
      "var code":"Gift Card Code",
      "var balance":"Gift Card Balance",
      "var status":"Status",
      "htmlescape var=$message":"Message",
      "var expiredat":"Expired At"}
      @-->

      <!--@styles
      body,td { background:#FFFFFF; margin:0; padding:0; color:#2f2f2f; font:13px/1.35em Verdana, Arial, Helvetica, sans-serif; }
      pre{ white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;}
      @-->
      {{template config_path="design/email/header_template"}}
      <div style="font:13px/1.35em Verdana, Arial, Helvetica, sans-serif;">
      <table cellspacing="0" cellpadding="0" border="0" width="98%"
      style="margin-top:10px; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; margin-bottom:10px;">
      <tr>
      <td align="center" valign="top">
      <!-- [ middle starts here] -->
      <table cellspacing="0" cellpadding="0" border="0" width="660">
      <tr>
      <td valign="top">
      <p>
      <strong>Dear {{var customer_name}},</strong>,<br/>
      Your request to process {{var amount}} has been approved and processed.</br>
      </p>
      </td>
      </tr>
      </table>
      </td>
      </tr>
      </table>
      </div>


      if i have invoice id as a variable, how can i attach my pdf invoice to this email?









      share














      I created a custom email and it's working fine like this:



          $data['amount'] = round($amount);
      $data['customer_name'] = $customer->getFirstname() . ' ' . $customer->getLastname();
      $data['customer_telephone'] = $customer->getMainTelephone();
      $data['customer_email'] = $customer->getEmail();
      $data['customer_credit_balance'] = round($creditBalance);
      $data['requested_at'] = $model->getRequestedAt();
      $data['customer_bank_account'] = $description;
      $storeName = $this->getStoreName();
      $storeEmail = $this->getStoreEmail();
      $senderInfo = [
      'name' => $storeName,
      'email' => $storeEmail
      ];
      $receiverInfo = [
      'name' => $data['customer_name'],
      'email' => $data['customer_email']
      ];
      $this->emailHelper->sendMail(
      $data,
      $senderInfo,
      $receiverInfo,
      'approve'
      );


      //emailHelper
      public function sendMail($emailTemplateVariables,$senderInfo,$receiverInfo,$type)
      {
      if ($type == 'request') {
      $typeId = self::XML_PATH_EMAIL_TEMPLATE_FIELD_REQUEST;
      } elseif ($type == 'approve') {
      $typeId = self::XML_PATH_EMAIL_TEMPLATE_FIELD_APPROVE;
      } else{
      $typeId = self::XML_PATH_EMAIL_TEMPLATE_FIELD_REJECT;
      }
      $this->temp_id = $this->getTemplateId($typeId);
      $this->inlineTranslation->suspend();
      $this->generateTemplate($emailTemplateVariables,$senderInfo,$receiverInfo);
      $transport = $this->_transportBuilder->getTransport();
      $transport->sendMessage();
      $this->inlineTranslation->resume();
      }


      template:



       <!--@subject Your Request is Approved @-->
      <!--@vars
      {"htmlescape var=$name":"Recipient Name",
      "htmlescape var=$sendername":"Sender name",
      "var code":"Gift Card Code",
      "var balance":"Gift Card Balance",
      "var status":"Status",
      "htmlescape var=$message":"Message",
      "var expiredat":"Expired At"}
      @-->

      <!--@styles
      body,td { background:#FFFFFF; margin:0; padding:0; color:#2f2f2f; font:13px/1.35em Verdana, Arial, Helvetica, sans-serif; }
      pre{ white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;}
      @-->
      {{template config_path="design/email/header_template"}}
      <div style="font:13px/1.35em Verdana, Arial, Helvetica, sans-serif;">
      <table cellspacing="0" cellpadding="0" border="0" width="98%"
      style="margin-top:10px; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; margin-bottom:10px;">
      <tr>
      <td align="center" valign="top">
      <!-- [ middle starts here] -->
      <table cellspacing="0" cellpadding="0" border="0" width="660">
      <tr>
      <td valign="top">
      <p>
      <strong>Dear {{var customer_name}},</strong>,<br/>
      Your request to process {{var amount}} has been approved and processed.</br>
      </p>
      </td>
      </tr>
      </table>
      </td>
      </tr>
      </table>
      </div>


      if i have invoice id as a variable, how can i attach my pdf invoice to this email?







      magento2 email email-templates invoice attachment





      share












      share










      share



      share










      asked 6 mins ago









      Shell SuiteShell Suite

      8451721




      8451721






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f262188%2fattach-invoice-pdf-attachment-to-custom-e-mail-in-magento-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f262188%2fattach-invoice-pdf-attachment-to-custom-e-mail-in-magento-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          What other Star Trek series did the main TNG cast show up in?

          Berlina muro

          Berlina aerponto