Search code examples
phpphpmailer

How to embed signature into the emails with php?


Thank you for taking time to read this.

How to embed signature into the emails with php?

Facts:

  1. The database column for signature is varchar(max)
  2. When I draw the signature in a php form signature field, It saves the signature data.

example signature input

Example of the data after the signature captured in the database: data:image/jsignature;base30,3S7flha3Z55hic5Y5b1vi63Z2952Ybmi40Z44Yaef630034hc5301a9810Z20Y748953112343_3OZ3aef97Y18jhd81Zdk62Y6gh95Z4761Y6b8Zbb52Y2b9Z38k9Y1a94Zdb9Y48j9Z87ee64Y46ih83

  1. I am using phpmail sender and tried to add the signature field as below
$mail_message        = '
<b>Doctor’s Signature:</b> '.{DoctorSignature}.' <br>
<b>date:</b> '.{date}.' 
'
  1. using jsignature for the signature (Not png)

Solution

  • This is a signature made with jsignature and needs to be parsed as such. I'm not sure if this work in E-Mail but the following code should do the trick:

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    <script src="https://cdn.jsdelivr.net/gh/brinley/jSignature@master/libs/jSignature.min.js"></script>
    <div id="PrintSignatureController">
    </div>
    
    <script>
    $(document).ready(function() {
      $("#PrintSignatureController").jSignature({
        'decor-color': 'transparent',
        'lineWidth': 1,
      });
      $("#PrintSignatureController").jSignature("importData", "data:image/jsignature;base30,3S7flha3Z55hic5Y5b1vi63Z2952Ybmi40Z44Yaef630034hc5301a9810Z20Y748953112343_3OZ3aef97Y18jhd81Zdk62Y6gh95Z4761Y6b8Zbb52Y2b9Z38k9Y1a94Zdb9Y48j9Z87ee64Y46ih83");
    });
    </script>
    

    I assume that an E-Mail does not execute JavaScript. In this case, I don't see a way around translating the signature first into base64, which can then be used in a tag.

    This is not as pointed but perhaps interesting: https://stackoverflow.com/a/47467731/11781125