The common infectionsChapter 17 of 3211 min read
WordPress Site Sending Spam Emails: Find the Script and Stop It
Trace unauthorized email to WordPress code, a scheduled task, a compromised mailbox or another server process. Preserve the evidence, remove the sender and verify normal mail still works.
By Hamza Ahmad AslamAI & WordPress Developer | Speed Optimization & Site Security

In this guide
A WordPress site sending spam emails has unauthorized outbound mail coming from WordPress code, a compromised hosting account or another mail-capable process under the same account. First identify the path the messages used, then preserve evidence and stop only the confirmed sender. After cleanup, verify both that the spam has stopped and that expected site email still works.
What does it mean when WordPress is sending spam emails?
It means mail associated with your site or hosting account is being sent without your authorization, but WordPress itself may not be the source.
A message using your domain in its visible From address does not prove that WordPress generated it. The source may be:
- malicious PHP inside the WordPress installation;
- a plugin or theme sending mail through normal WordPress functions;
- a scheduled WordPress task;
- stolen SMTP or mailbox credentials;
- another application under the same hosting account;
- another server-side process that can submit email.

A sender using WordPress can call wp_mail() (opens in a new tab), which sends email through WordPress's configured mail system. PHP code can also call PHP's mail() function (opens in a new tab) directly. An SMTP plugin may route WordPress mail through a separate provider.
That distinction matters because disabling one WordPress plugin will not stop a compromised mailbox or unrelated server process.
What signs show that my site or hosting account is sending spam?
The strongest signs are records of messages you did not authorize, especially when their timestamps line up with activity on the server.
Check for:
- abuse or suspension notices from your host or mail provider;
- unfamiliar recipients or subjects in outbound-message records;
- a growing mail queue reported by the host;
- large numbers of bounce or delivery-failure messages;
- mail-provider rejections after unusual sending;
- customers reporting phishing or spam that appears to come from your domain;
- unexpected bursts of outgoing mail at times your site normally sends little or nothing.
Do not treat a bounce alone as proof. Spoofed mail can use your address without passing through your WordPress installation.
Record several known spam timestamps, including the timezone shown by the provider. You will use those times to compare mail records, scheduled events and file changes.
How can a hacked WordPress site send spam?
A hacked WordPress site can send spam when attacker-controlled PHP, a compromised plugin or a scheduled callback invokes an available mail path.
Common mechanisms include:
- injected PHP that calls
wp_mail()ormail(); - modified plugin or theme files;
- a vulnerable plugin used to add or execute attacker-controlled code;
- stolen WordPress administrator credentials used to install or modify code;
- a malicious WP-Cron event that repeatedly calls a mail-sending callback;
- stolen credentials for an SMTP service configured by the site.
WP-Cron is WordPress's scheduled-task system. WordPress checks its scheduled events when requests trigger WP-Cron, and plugins can register their own hooks.
A spam sender may therefore run repeatedly even when nobody is logged in.
If you have already identified a vulnerable plugin as the entry path, chapter 15, Hacked Through a Vulnerable Plugin: Find It and Close the Hole, covers closing that vulnerability after containment.
How do I find out whether the messages came through WordPress?
Match a known spam message to records from each possible sending path instead of assuming the From address identifies the source.
-
Record the message timestamp, recipient, subject and any message ID your mail provider exposes. Keep the timezone with the timestamp.
-
Check the outbound-message or mail-activity records supplied by your SMTP provider, mailbox provider or host. Look for the same recipient and time.
-
If the provider identifies an authenticated mailbox or SMTP credential, investigate that account before changing WordPress code.
-
If the host identifies a local PHP process, script path or hosting account, record that information before removing anything.
-
Compare the timestamp with your WordPress logs, WP-Cron events and file modification times.

On shared hosting, ask the host which site or process submitted the message if their logs expose that information. A compromised mailbox or a second application under the same account can make the problem look like a WordPress infection.
Which WordPress code can send email?
WordPress core, plugins and themes can use wp_mail() for legitimate messages, while arbitrary PHP can also use other mail mechanisms.
Normal wp_mail() uses include password-reset messages, account notifications and plugin-generated transactional mail. A call to the function is therefore evidence of a mail-capable code path, not evidence that the code is malicious.
Search your own plugin and theme code for mail calls:
grep -RInE --include='*.php' 'wp_mail[[:space:]]*\(|(^|[^[:alnum:]_])mail[[:space:]]*\(' wp-content
GNU grep documents -R for recursive searching, -I for ignoring binary matches, -n for line numbers and -E for extended regular expressions. Review each match in context.
If you do not have shell access, use the host's file manager search feature if it can search file contents. Otherwise download the relevant plugin, theme and must-use plugin directories to a safe workstation and search them there.
A normal-looking wp_mail() call does not explain the incident until its subject, recipient construction, trigger or timing matches the unauthorized messages.
How do I check plugins, themes and scheduled events for the source?
Inventory installed code and WP-Cron events, then compare unfamiliar entries with the spam timeline.
Check installed plugins and themes
Run:
wp plugin list --fields=name,status,version,update,update_version --format=table --skip-plugins --skip-themes
wp theme list --fields=name,status,version --format=table --skip-plugins --skip-themes
--skip-plugins --skip-themes prevents normal plugins and themes from loading during these investigation commands. Must-use plugins still load, so inspect wp-content/mu-plugins separately if anything remains suspicious.
Without shell access, compare the same inventory in wp-admin under Plugins and Appearance > Themes. Also inspect wp-content/plugins, wp-content/themes and wp-content/mu-plugins in the host's file manager for directories that are absent from your expected deployment.
Record every plugin and theme version before changing anything.
Check WP-Cron
The documented wp cron event list (opens in a new tab) command lists scheduled events and supports the fields used here:
wp cron event list --fields=hook,next_run_gmt,recurrence --format=table --skip-plugins --skip-themes
Example output, illustrative:
+----------------------------+---------------------+------------+
| hook | next_run_gmt | recurrence |
+----------------------------+---------------------+------------+
| wp_version_check | 2026-09-28 15:00:00 | 12 hours |
| example_store_cleanup | 2026-09-28 15:05:00 | hourly |
| midnight_mail_dispatch_x9 | 2026-09-28 15:07:00 | 5 minutes |
+----------------------------+---------------------+------------+

A strange hook name alone does not prove compromise. Find which plugin, theme or must-use plugin registers it and compare its schedule with your known spam timestamps.
wp-admin does not provide a core screen that lists all WP-Cron events. If you have no command-line access, give this read-only command to your host and ask for its output rather than installing another plugin during the incident.
How do I check the server for a malicious mail script?
Look for changed PHP files around the first known spam event, then check WordPress and plugin files against known checksums.
From the WordPress directory, set START_TIME to a time before the suspicious sending began and END_TIME to a time after the period you are investigating:
find . -type f -name '*.php' -newermt 'START_TIME' ! -newermt 'END_TIME' -print
GNU find documents -newermt for comparing modification timestamps. This command only lists files. It changes nothing.
Without shell access, use the host's file manager to sort PHP files by modification time around the same window. Do not delete a file because its modification time is recent.
Next run integrity checks:
wp core verify-checksums --include-root --skip-plugins --skip-themes
wp plugin verify-checksums --all --skip-plugins --skip-themes
wp core verify-checksums (opens in a new tab) compares core files with WordPress.org checksums. --include-root also warns about unexpected items in the WordPress root.
wp plugin verify-checksums (opens in a new tab) checks plugin files against WordPress.org checksums. A checksum mismatch deserves investigation, but custom or third-party code must be compared with its own trusted release because WordPress.org cannot verify arbitrary private packages.

If the suspicious PHP sits outside a normal plugin or theme, or you find obfuscated loaders, hidden PHP or unfamiliar execution paths, continue with chapter 11, How to Find a Backdoor in WordPress: Web Shells and Hidden PHP.
How do I stop the spam without destroying evidence?
Preserve the relevant files and logs first, then disable the confirmed sender or ask the provider to block abusive outbound mail.
-
Save the provider's outbound records, abuse notice and several sample message details.
-
Copy a confirmed suspicious file to
/SAFE_PATH, which must be a private directory outside every web root:
cp -a -- SUSPECT_FILE /SAFE_PATH/
Replace SUSPECT_FILE with the exact path you identified. cp -a makes an archival copy and attempts to preserve file attributes.
Without shell access, download the file through the host's file manager before changing it. Store the copy somewhere the web server cannot serve.
-
If the host can suspend outbound mail for the affected hosting account or script while leaving the site available for investigation, ask them to do that. Tell them you are preserving evidence and need the source process or script path from their logs.
-
If one SMTP credential or mailbox is confirmed as the sender, disable or rotate that credential through its provider and terminate sessions where the provider offers that control.
Do not permanently disable every WordPress email path unless containment requires it. Stores and membership sites may depend on password, account, order or enrollment messages.
How do I remove the script or account responsible?
Remove only the confirmed malicious component, then close the access that allowed it to appear.
For a standalone malicious file that you have already copied to /SAFE_PATH, remove that exact file:
rm -i -- SUSPECT_FILE
Replace SUSPECT_FILE with the confirmed malicious path. rm -i asks before removal. This command deletes that file, so confirm the displayed path before answering yes.
Without shell access, delete only that confirmed file through the host's file manager after downloading the evidence copy. Then check that the path no longer exists.
If a WordPress.org plugin has been modified, replace it with the same trusted release rather than keeping edited files:
wp plugin install SLUG --version=VERSION --force --skip-plugins --skip-themes
Put the plugin's WordPress.org slug in SLUG and its previously installed release in VERSION. --force overwrites the installed plugin files, so preserve suspicious files first. Do not use this command for a private or commercial package that is not distributed through WordPress.org.
If a malicious scheduled event remains after its callback has been identified and preserved, remove that hook:
wp cron event delete HOOK --skip-plugins --skip-themes
Replace HOOK with the confirmed unauthorized hook. The documented wp cron event delete (opens in a new tab) command deletes all scheduled events for that hook, so do not use it for an unfamiliar hook until you know what registered it.
Without command-line access, ask the host to execute the exact command after you provide the confirmed hook name.
If an unauthorized WordPress administrator enabled the mailer, remove that account as part of chapter 10, How to Find and Remove Hidden Admin Users in WordPress. If mailbox credentials were stolen, change them at the mail provider rather than changing WordPress alone.
Chapter 6, How Was My WordPress Site Hacked? Finding the Entry Point in the Logs, covers tracing the initial access if the entry path remains unknown.
How do I verify that unauthorized mail has stopped?
Verify the result in the same records that proved the unauthorized sending was happening.
-
Note the exact containment time and timezone.
-
Recheck the provider or host's outbound records after that point.
-
Confirm that no new messages match the unauthorized subjects, recipients, authenticated account or sending script.
-
Run the cron inventory again if a scheduled event was involved:
wp cron event list --fields=hook,next_run_gmt,recurrence --format=table --skip-plugins --skip-themes
The deleted malicious hook should be absent. Expected WordPress hooks should remain.
- Trigger one expected application message, such as a password-reset email to an address you control or a safe test transaction appropriate to the site. Confirm that the message appears in the provider's records and reaches the test mailbox.
If unauthorized mail resumes, treat that as evidence of persistence. Chapter 19, WordPress Malware Keeps Coming Back: Find the Reinfection Source, covers that investigation.
How do I repair mail delivery after the infection is gone?
Repair delivery by following the sending provider's documented recovery process after you have proved the abusive sending has stopped.
Check the provider account for:
- sending restrictions or suspension;
- rejected authentication;
- domain or sender verification failures;
- reputation or blocklist notices the provider identifies;
- changed SMTP credentials or routing settings.
Restore only the authentication records and credentials documented by the provider you use. Do not copy SPF, DKIM or DMARC values from another site because those values are provider and domain specific.
Then send a small expected test message and confirm it appears in the provider's records.
A successful call to wp_mail() means WordPress's mail method accepted the request without reporting an error. The WordPress documentation states that this does not prove the recipient received the message.
How do I stop spam mail from returning?
Prevent recurrence by removing persistence, closing the entry path and watching for unexpected outbound activity.
Complete these checks after cleanup:
- investigate the vulnerability or stolen credential that provided access;
- remove backdoors and unauthorized administrators;
- replace altered core, plugin and theme files with trusted copies;
- rotate compromised hosting, WordPress, mailbox, SMTP and deployment credentials as applicable;
- update vulnerable software after preserving the incident state;
- review WP-Cron for unexplained hooks;
- keep outbound-message records or alerts where your provider supplies them.
Use How to clean a hacked WordPress site and stop it happening again for the wider cleanup sequence. After the infection is removed, follow WordPress security hardening: a practical checklist for 2026 for the post-incident configuration work.
Chapter 27, How to Secure WordPress After a Hack, covers the guide's full hardening stage. Chapter 28 covers ongoing WordPress security monitoring.
What changes for different kinds of WordPress sites?
The investigation is the same, but the legitimate mail baseline and the scope of containment differ by site type.
WooCommerce stores: Separate unauthorized mail from legitimate order, refund, account and customer notifications before disabling any sender. If the compromise also touched checkout code or payment data, return to chapter 16, WooCommerce Credit Card Skimmer: Detect and Remove Checkout Malware, and follow the incident steps there.
Shared hosting: Check mail activity for the entire hosting account. Another WordPress installation, other application or compromised mailbox under that account may be the true source.
Membership and course sites: Separate spam from registration, password-reset, enrollment and course notifications. Blocking all application mail can stop users from receiving account access messages.
News sites: Check newsletter and publishing integrations separately. High outbound volume may be expected, while stolen sending credentials can still turn a normal integration into an abuse path.
What should I investigate after stopping the spam sender?
Investigate any destination, login page or attachment promoted by the spam because the mail campaign may be tied to content hosted on the compromised site. Chapter 18, Phishing Pages on a WordPress Site: Find and Remove Them, shows how to find and remove those pages.
Frequently asked questions
Why is WordPress sending emails I did not create?
Unauthorized mail can come from modified PHP, a compromised plugin, a scheduled WordPress task or stolen mail credentials. Match message timestamps with outbound-mail records, WP-Cron events and changed files before deciding which component sent it.
Can WordPress send spam without an SMTP plugin?
Yes. WordPress can call wp_mail() without a separate SMTP plugin, and PHP code can also use other available mail mechanisms. The exact delivery path depends on the site's PHP and hosting mail configuration.
Can a hacked plugin send email through WordPress?
Yes. Plugin PHP can call the same WordPress mail functions used for legitimate notifications. Check the plugin's files, scheduled hooks and modification history against the known spam timestamps.
How do I know if spam came from WordPress or my email account?
Use the mail provider or host's outbound records. A record tied to an authenticated mailbox points toward that account, while a local script or PHP path points toward server-side code. A visible From address alone cannot make that distinction.
Should I disable all outgoing WordPress email during cleanup?
Disable or restrict mail if that is necessary to stop ongoing abuse, but preserve evidence first and avoid leaving all mail disabled permanently. Stores, membership sites and other applications may require legitimate transactional messages.
Why are my legitimate WordPress emails blocked after a hack?
A mail provider may restrict sending after detecting abusive traffic, and recipient systems may reject or filter messages after an incident. Prove that the unauthorized sender is gone, then follow your sending provider's documented process for restoring authentication, sending access or reputation.
Sources
- wp_mail() – Function (opens in a new tab)
- wp cron event list – WP-CLI Command (opens in a new tab)
- wp cron event delete – WP-CLI Command (opens in a new tab)
- wp plugin list – WP-CLI Command (opens in a new tab)
- wp theme list – WP-CLI Command (opens in a new tab)
- wp core verify-checksums – WP-CLI Command (opens in a new tab)
- wp plugin verify-checksums – WP-CLI Command (opens in a new tab)
- wp plugin install – WP-CLI Command (opens in a new tab)
- Cron – Plugin Handbook (opens in a new tab)
- PHP mail() – Manual (opens in a new tab)
- GNU Grep manual (opens in a new tab)
- GNU Findutils manual (opens in a new tab)
How this article was made: drafted with AI assistance from a researched brief, then checked against primary documentation before publishing.
Message
Ask me about your site
Tell me what is wrong or what you need built. I reply by email.