To send an invoice or receipt by email API, generate the document as a PDF, encode it as base64, and attach it to one API request along with a short message that repeats the essentials: number, amount, due date and how to pay. Send it from your own verified domain, make the send idempotent with the invoice number, and include a link to the invoice online for anyone whose mail system strips attachments.
Receipt or invoice?
| Receipt | Invoice | |
|---|---|---|
| Purpose | Confirms you were paid | Asks to be paid |
| Sent when | Payment succeeds | A billing period closes or work is delivered |
| Key fields | Amount paid, date, method, what for | Amount due, due date, payment details, line items |
| Tax fields | Often required for business buyers | Usually required; rules vary by country |
Many SaaS products send one email per charge that serves as both. Check local rules before relying on that, because some countries require a formal invoice with specific fields and numbering.
What the email body should say
The PDF is the record; the email is what people read. Repeat the important facts in the body so nobody needs to open the attachment to know what it is:
- Invoice or receipt number
- Amount and currency
- Due date, or date paid
- What it is for (“Acme Team plan, November 2026”)
- How to pay, or how the payment was made
- A link to view it online, and who to contact about it
Best practices
- PDF only. Gateways block or quarantine ZIP, HTML and macro-enabled Office attachments.
- Name the file clearly.
acme-invoice-1042.pdf, notdocument.pdf. - Keep it small. Render text, not scanned images. Large attachments slow delivery and some receivers reject big messages.
- Calm wording. “Your invoice is ready” rather than “URGENT: payment overdue!!”. See spam trigger words.
- Send to billing contacts. Let customers add a billing address that differs from the account owner, and CC it.
- Reply-To your billing team. Invoice replies are questions about money; answer them.
Invoice email template
From: Acme Billing <billing@acme.com>
Reply-To: billing@acme.com
Subject: Invoice INV-1042 from Acme, $39.00 due 30 November
Hi Sam,
Your invoice for the Acme Team plan (November 2026) is attached.
Invoice: INV-1042
Amount: $39.00
Due: 30 November 2026
It will be charged to your card ending 4242 on the due date.
View or download it online: https://app.acme.com/billing/INV-1042
Questions? Reply to this email.
Acme Inc, 1 Example Street, Springfield
Sending an invoice with PDF attachment in PHP
This uses PHP’s built-in curl and the Mailcandor email API. The attachments array takes a filename, the base64 content and a content type.
<?php
function sendInvoice(array $invoice, string $pdfPath): string
{
$payload = [
'from' => 'Acme Billing <billing@acme.com>',
'to' => $invoice['email'],
'reply_to' => 'billing@acme.com',
'subject' => "Invoice {$invoice['number']} from Acme, {$invoice['amount']} due {$invoice['due']}",
'html' => "<p>Your invoice {$invoice['number']} for {$invoice['amount']} is attached.</p>"
. "<p>Due: {$invoice['due']}</p>"
. "<p><a href=\"https://app.acme.com/billing/{$invoice['number']}\">View it online</a></p>",
'text' => "Your invoice {$invoice['number']} for {$invoice['amount']} is attached. Due {$invoice['due']}.\n"
. "View it online: https://app.acme.com/billing/{$invoice['number']}",
'attachments' => [[
'filename' => "acme-invoice-{$invoice['number']}.pdf",
'content' => base64_encode(file_get_contents($pdfPath)),
'content_type' => 'application/pdf',
]],
'tags' => [['name' => 'type', 'value' => 'invoice']],
];
if (!empty($invoice['billing_cc'])) {
$payload['cc'] = $invoice['billing_cc'];
}
$ch = curl_init('https://api.mailcandor.com/v1/emails');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('MAILCANDOR_KEY'),
'Content-Type: application/json',
"Idempotency-Key: invoice-{$invoice['number']}",
],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$body = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status !== 202) {
throw new RuntimeException("{$body['error']['type']}: {$body['error']['message']}");
}
return $body['id'];
}
To send an invoice at a set time, such as 9:00 on the first of the month in the customer’s timezone, add 'scheduled_at' => '2026-12-01T09:00:00Z'. Scheduled emails can be moved or canceled until they go out. Note that the batch endpoint does not accept attachments or scheduling, so invoices go one request each; the idempotency key makes a billing job safe to rerun.
Receipts after every charge
Receipts are simpler than invoices: no due date, no payment instructions. Trigger them from your payment provider’s “payment succeeded” webhook, not from your own billing code, so a receipt is only sent for money that actually arrived. Use the charge or payment id as the idempotency key, because payment webhooks are often delivered more than once. For stores, the receipt is often merged into the order confirmation. For failed payments, send a separate, plainly worded notice with a link to update the card, and stop after a few attempts rather than emailing daily.
Why this works well on Mailcandor
The deliverability coach checks your domain’s SPF, DKIM, DMARC and return path, and can run a content check on a draft before you send. Delivery and bounce events arrive by webhook tagged invoice, so your billing system can flag customers whose invoices bounce before the due date passes. Pricing is per email with no seat or domain fees; see pricing.
Common pitfalls
- No body text. An email that is only an attachment looks like malware.
- Sending from a no-reply address. Customers reply with questions about the charge.
- Rerunning a billing job without idempotency. Duplicate invoices cause duplicate payments and refund work.
- Attachment only, no link. Some corporate systems strip attachments. Always offer the online copy.
- Personal data in tags or subjects you log. Keep tags to types and ids.
- Mismatched domains. Links, From address and payment page on unrelated domains look like phishing.