Where outgoing spam comes from
Most site owners think of spam as junk arriving in their inbox, but the reverse happens just as often: your own website quietly sends thousands of messages around the world. The usual cause is a PHP script uploaded through a vulnerable plugin, an outdated CMS or a stolen FTP password. That script calls the server's standard mail function and sends advertising or phishing in the name of your domain and your server's IP address.
The second common source is a compromised mailbox. If a mailbox such as info@example.uz has a weak password, or malware on an employee's computer has stolen it, spammers simply authenticate over SMTP and send mail directly. In that case the website files may be perfectly clean. So the first job is to work out which path is being abused: a PHP script or an SMTP login.
Signs that your site is sending spam
The first signal is usually bounced mail. Your inbox fills with Undelivered Mail Returned to Sender or Delivery Status Notification messages for addresses you never wrote to. Next, your normal mail starts landing in Gmail or Outlook spam folders because the server IP has lost its reputation. Finally, your hosting provider may notify you that outgoing mail has been limited or the account suspended.
A small building-supplies shop in Tashkent, for example, sent order confirmations from a form on its website. One day customers complained that confirmations stopped arriving, while the shop's mailbox filled with bounces from foreign addresses. It turned out that an outdated form plugin had allowed a single PHP file into the uploads folder, and that file was sending thousands of messages per hour.
Checking the mail queue and logs
On a VPS or your own server running Exim, start by looking at the queue. Normally it is empty or holds a few messages; during a spam run it holds thousands. These commands show the queue size, the most active senders and the directories PHP scripts were launched from:
# number of messages in the queue
exim -bpc
# top sender addresses
exim -bp | grep '<' | awk '{print $4}' | sort | uniq -c | sort -rn | head
# working directories of local senders (RHEL/AlmaLinux)
grep 'cwd=' /var/log/exim/main.log | awk -F'cwd=' '{print $2}' | awk '{print $1}' | sort | uniq -c | sort -rn | head
Exim records the working directory of every locally submitted message in the cwd= field, so a path like /var/www/misol/data/www/misol.uz/wp-content/uploads repeated thousands of times points straight at the culprit. On Debian and Ubuntu the log is usually /var/log/exim4/mainlog. If PHP has mail.add_x_header enabled, each message also carries an X-PHP-Originating-Script header with the script name.
# headers of one queued message (ID from exim -bp)
exim -Mvh 1tXyZa-000Abc-1Q
# count script names found in queued messages
grep -rh 'X-PHP-Originating-Script' /var/spool/exim/input/ | sort | uniq -c | sort -rn | head
On shared hosting you will not have these commands, but the ISPmanager file manager and logs still help. Open one of the bounces and read the original headers inside it; they often reveal the script name or the mailbox used for SMTP login, which lets support analyse server logs much faster.
Finding and removing the script
Once you know the directory, look for recently changed PHP files. Spam scripts often have random names or hide in uploads, images or wp-includes, where executable PHP should not appear:
find ~/www -name '*.php' -mtime -7 -ls
find ~/www/misol.uz/wp-content/uploads -name '*.php'
grep -rlE 'eval\(base64_decode|gzinflate\(|mail\(\$_POST' ~/www --include='*.php'
Copy the file outside the web root before deleting it so you can later work out how the attacker got in. Removing one file is rarely enough, because attackers leave several hidden entry points that restore each other. Scan the whole site, reinstall the CMS core from the official source, delete unused plugins and themes, and update everything else.
Clearing the queue and resetting passwords
# remove all messages from one sender
exiqgrep -i -f 'spam@misol.uz' | xargs exim -Mrm
# remove frozen messages older than one day
exiqgrep -z -i -o 86400 | xargs exim -Mrm
Then change every password: hosting panel, FTP, database, CMS administrators and each mailbox. If the abuse came through SMTP, reset that mailbox immediately and scan the employee's computer, or the new password will be stolen too. Add a CAPTCHA or a hidden honeypot field to contact and registration forms, since bots can also abuse an unprotected form.
SPF, DKIM, DMARC and blacklists
Set up SPF, DKIM and DMARC for your domain. They do not stop spam by themselves, but they tell receiving servers which sources may send on your behalf, and DMARC reports reveal foreign sending early. You can add DNS records yourself in the sayt.uz cabinet. If the spam ran for hours, the server IP is probably listed on blacklists such as Spamhaus. Request delisting only after the source is fully closed; otherwise the IP is relisted quickly and the next removal gets harder. On shared hosting the provider usually handles this, so tell support exactly what you found and fixed.