-2

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)
4
  • @KenLee Thank you for your comment, I see this error after I send the email : Undefined variable: arr
    – Christiano
    Commented Mar 16, 2022 at 23:56
  • @KenLee I think the reason is that I am using jsignature not png ?
    – Christiano
    Commented Mar 17, 2022 at 0:08
  • See whether it helps convert_base30_to_png (After conversion, just use the converted png in your email)
    – Ken Lee
    Commented Mar 17, 2022 at 2:10
  • However you are generating the signature in the browser, it should be submitted to PHP as a PNG image. After that, you can treat it just like any other image attachment, exactly as shown in the PHPMailer upload example. No, you can't run javascript within PHP, nor within email, so this conversion needs to happen on the client.
    – Synchro
    Commented Mar 17, 2022 at 9:54

1 Answer 1

0

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

4
  • Thank you for the answer, I am not sure but it does not unbdrestand 'decor-color': 'transparent', 'lineWidth': 1, error shows 'Parse error: syntax error, unexpected 'decor' (T_STRING) '
    – Christiano
    Commented Mar 17, 2022 at 0:16
  • Did you copy and paste it into PHP? You used single quotes for the inserting the HTML. Perhaps you need to escape my single quotes or replace them with double quotes? Commented Mar 17, 2022 at 0:29
  • Yeah, I copy and pasted it and tried using " instead of ' and also tried to escape all ' and used \' instead . With both methods, I received the email but with no signature
    – Christiano
    Commented Mar 17, 2022 at 1:00
  • No, you can't run JS inside email, and I'd expect that any form submission performed from JS would include binary image data, not an encoded format (that you would have to decode before use).
    – Synchro
    Commented Mar 17, 2022 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.