PHP对接DocuSign:如何格式化签署人自定义邮件正文?
Hey there! Let's sort out that auto-indent issue you're facing with your DocuSign recipient emails. Since you're restricted to plain-text content (your $pdEmailBody doesn't support HTML), here are a few practical fixes to get all your text left-aligned with zero indentation:
1. Strip Leading Whitespace From Every Line
DocuSign's plain-text renderer often picks up accidental leading spaces or tabs in your content. You can clean this up easily using PHP's array functions to trim each line individually:
// Split the body into lines, trim whitespace from each line, then rejoin $cleanedEmailBody = implode("\n", array_map('trim', explode("\n", $pdEmailBody)));
Use this cleaned $cleanedEmailBody value instead of the original $pdEmailBody when configuring your RecipientEmailNotification.
2. Standardize Line Endings
Inconsistent line breaks (like mixing \n and \r\n) can sometimes trigger unexpected rendering behavior. Stick to a single line ending format—either \n (Unix/Linux) or \r\n (Windows) depending on your environment—and remove any unnecessary empty lines between paragraphs.
3. Audit Your Source Content
Double-check where $pdEmailBody originates. If it's pulled from a database, text file, or user input, there might be hidden leading whitespace that's sneaking into your emails. Manually inspect the raw content to confirm no unintended spaces are at the start of each paragraph.
Updated Code Snippet
Here's how to integrate the cleaned body into your existing code:
// First clean up the email body $cleanedEmailBody = implode("\n", array_map('trim', explode("\n", $pdEmailBody))); $signer1 = new \DocuSign\eSign\Model\Signer([ 'email' => $pdEmail, 'name' => $pdName, "recepient_id" => "1", 'routing_order' => "1", 'email_notification' => new \DocuSign\eSign\Model\RecipientEmailNotification([ 'email_subject' => $pdEmailSub, 'email_body' => $cleanedEmailBody ]) ]);
This should eliminate those annoying auto-indents and keep your email content neatly left-aligned for all recipients.
内容的提问来源于stack exchange,提问作者shah

