| 开发者 | simmotorlp |
|---|---|
| 更新时间 | 2026年11月26日 16:01 |
| PHP版本: | 8.0 及以上 |
| WordPress版本: | 7.2 |
| 版权: | GPLv2 or later |
| 版权网址: | 版权信息 |
wp_mail() that routes WordPress email through the Mailtrap Email Sending API instead of SMTP. It is purpose-built for Mailtrap — not a generic SMTP plugin with a Mailtrap preset — so it exposes Mailtrap-native features that SMTP cannot: bulk vs transactional stream routing, email categories, custom variables for tracking, suppression lists, and domain verification status.
Why HTTP API instead of SMTP?
send.api.mailtrap.io for transactional mail and bulk.api.mailtrap.io for bulk mail — automatically: newsletters from Newsletter, FluentCRM, Icegram Express and Groundhogg are recognized, and anything else can be routed by category, header or filter.wp_remote_post).wp_mail() — works with WooCommerce, Contact Form 7, Gravity Forms, and any plugin that uses WordPress mail.swifttrap/v1/webhook.SWIFTTRAP_MAILTRAP_TOKEN constant in wp-config.php.wp swifttrap (test, stats, prune-logs, send-suppression-sync).template_uuid.swifttrap_mailtrap_email_category — override the auto-detected email category.swifttrap_mailtrap_use_bulk_stream — force a message into the bulk or transactional stream (receives the category, the settings and the email itself).swifttrap_mailtrap_bulk_source — tell the plugin that an email comes from your own newsletter tool.swifttrap_mailtrap_fallback_to_wp_mail — decide per message whether a refused email may go out through the default mailer.X-SwiftTrap-Stream: bulk (or transactional) on any wp_mail() call picks the stream for that message; the header is never forwarded to the recipient.swifttrap_mailtrap_template — send via a Mailtrap template by template_uuid.swifttrap_mailtrap_custom_variables — attach tracking metadata to outgoing emails.send.api.mailtrap.io and bulk.api.mailtrap.io. Account stats and email logs are fetched from mailtrap.io/api/accounts and mailtrap.io/api/email_logs. See the Mailtrap Privacy Policy. No data is sent anywhere else.
swifttrap-for-mailtrap folder to /wp-content/plugins/.Generic mailer plugins treat Mailtrap as one provider among many: through SMTP credentials, or through the transactional API only. SwiftTrap is built for Mailtrap alone and uses what is specific to it: bulk vs transactional stream routing (including automatic routing of newsletters), categories, custom tracking variables, template UUIDs, and live suppression-list visibility. Use SwiftTrap if you want Mailtrap-native behavior; use a generic SMTP plugin if you want a one-config-fits-all-providers setup.
Yes — use the swifttrap_mailtrap_template filter to send via a template_uuid. The template variables can be passed through Mailtrap's standard template-variables payload.
Go to Mailtrap → Settings and tick Send newsletters through the bulk stream. Campaign emails sent by Newsletter (The Newsletter Plugin), FluentCRM, Icegram Express and Groundhogg are then recognized and sent through bulk.api.mailtrap.io; password resets, orders, form notifications, signup confirmations and all other email keep using send.api.mailtrap.io. Nothing has to be configured in the newsletter plugin — leave it on its default "send through WordPress" delivery. The same API token is used for both streams.
MailPoet is the exception: it sends with its own mailer and never passes through wp_mail(), so no wp_mail() plugin can route it.
Strongest first: the swifttrap_mailtrap_use_bulk_stream filter; the X-SwiftTrap-Stream: bulk (or transactional) header on a wp_mail() call; newsletter plugin detection (when switched on); the category table on the settings screen, where the promotional category goes to the bulk stream by default. Everything else goes to send.api.mailtrap.io.
Mailtrap keeps unsubscribes and bounces separately for each stream, and so does the plugin: somebody who unsubscribed from your newsletter still receives a password reset.
Log in to mailtrap.io, open your sending domain, go to API Tokens, and create a token with sending permissions. After saving, the token is never displayed again. To keep it out of the database, add define( 'SWIFTTRAP_MAILTRAP_TOKEN', 'your-token' ); to wp-config.php instead.
WordPress falls back to its default wp_mail() handler. No emails are silently dropped.
The plugin retries briefly, then reports the failure to WordPress (wp_mail_failed, with the reason Mailtrap gave). With Use the default WordPress mailer as a backup ticked (the default) the message is then handed to the default mailer; untick it if email must never leave through your web host — wp_mail() then returns false.
No. SwiftTrap calls the Mailtrap REST API directly via the WordPress HTTP API. Total plugin size is around 30 KB.
Email data (recipients, subject, body, attachments) goes to send.api.mailtrap.io and bulk.api.mailtrap.io. Account stats are fetched from mailtrap.io/api/accounts. See the Mailtrap Privacy Policy.
The plugin refuses attachments above the size you set (1–25 MB per file, 25 by default). Mailtrap itself limits the whole message, attachments included, to 10 MB by default (more on request on higher plans), so lower the setting if your plan has the default limit.
X-SwiftTrap-Stream: bulk / transactional header picks the stream for one wp_mail() call. New swifttrap_mailtrap_bulk_source filter; swifttrap_mailtrap_use_bulk_stream now also receives the email.swifttrap_mailtrap_fallback_to_wp_mail filter.wp-config.php (SWIFTTRAP_MAILTRAP_TOKEN). A saved token is no longer printed into the settings page; leave the field empty to keep it.wp_mail() returned a truthy error object instead of false when an email had an invalid address, a missing attachment or only suppressed recipients, so the calling plugin believed it was sent.wp_mail_from / wp_mail_from_name filters are applied to each message. They were read once per request, so a From address set by WooCommerce or a form plugin for its own email was ignored or leaked into other emails.SWIFTTRAP_BLOCK_BULK were still delivered by the default mailer.'name.pdf' => $path keep their name; inline images ($embeds, WordPress 6.9+) are sent; error messages no longer contain server paths.?a=1&b=2 instead of ?a=1&b=2, and a link whose text is not its URL keeps the URL in brackets (password reset emails used to show only "address"). Line breaks follow <br> and block ends.Mailtrap-Signature HMAC-SHA256 header instead of a header Mailtrap never sends. Every real delivery-tracking webhook call was being rejected outright since the feature shipped in 2.4.0.{"events": [...]} envelope correctly, so verified events reach do_action('swifttrap_mailtrap_webhook_event', ...)./api/billing/usage endpoint instead of a stale account-scoped path that returned no data.GET /api/email_logs).do_action('swifttrap_mailtrap_webhook_event', $event) for every delivery event, allowing third-party integrations without modifying the plugin.type field, so the dashboard shows real BOUNCE / COMPLAINT / UNSUBSCRIBE / MANUAL counts instead of marking every record as manual.swifttrap/v1/webhook) for tracking delivered, bounced, opened, and clicked statuses.null in pre_wp_mail on API failure so native wp_mail sends the email instead.wp swifttrap (test, stats, prune-logs, send-suppression-sync).email/mail/smtp with targeted mailtrap, transactional-email, email-api, wp-mail, email-logswifttrap_mailtrap_template filter for Mailtrap template supportswifttrap_mailtrap_custom_variables filter for email tracking metadataswifttrap_mailtrap_get_account_id() with transient caching