I'm having trouble showing line breaks in Stripe's email receipts. The email description is generated via PHP and <br>
, \r\n
are displayed literally.
I also tried nl2br
but since that displays <br>
I'm sure it won't work.
PHP
$detail = "$name\r\n";
$detail .= "Length: $length,";
$detail .= " Width: $width,";
$detail .= "Color: $color,";
$detail .= "Qty: $qty\r\n";
$detail .= "Price: $price\r\n";
echo nl2br($detail);
How can I display line breaks on my Stripe email receipt using PHP?
Set up a custom email domain To start sending emails from your own domain, complete the following steps: Add your domain in the Dashboard. Verify your domain to allow sending. Set your sending domain as your domain.
Stripe allows you to customize (as well as preview) email receipts, hosted invoices, invoice PDFs, and more, in your Branding settings.
Receipts in test modeStripe can automatically send email receipts after a successful payment, or when you refund one. This is done by providing an email address when making the API request, using the email address of a Customer object, or updating a PaymentIntent with a customer's email address after checkout.
Stripe integrations handle complicated processes. The API uses a single object to track each process. You create the object at the start of the process, and after every step you can check its status to see what needs to happen next. For instance, while completing a payment, a customer might try several payment methods.
Edit: It looks like Stripe began supporting line breaks at some point over the past few years, see comments on this answer.
Previous answer:
I was trying to achieve the same thing and ended up talking with their support. In short:
\n
will be ignored.As I see it, you have 3 options within these current constraints:
Use commas (or whatever) for items on one long line:
Shampoo - $5.00, Toothbrush - $2.00, Soap - $3.00 --------------- $10.00
Send your own email.
This does give you an invoice + a receipt email like this:
Shampoo ----- $5.00
Toothbrush -- $2.00
Soap -------- $3.00
Total ------ $10.00
But there's 1 huge caveat to #3. Invoices are automatically created by Stripe for all outstanding invoice items and subscription plans that a customer might have. This occurs 1 hour before an invoice should be charged (this is according to the interval that you might have setup for a plan, or perhaps at the end of the month if you're only dealing with invoice items, I'm not sure in the latter case.). This means you could technically have a customer checking out that gets charged for more items within the current transaction then they were anticipating, which just smells of bad design and a bad solution to a simple problem.
So, I'm sticking with comma separated items on 1 line for a current project, and doing custom emails whenever a client has the budget for us to build them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With