Site AI Auditby Internet Solutions

Email Header Injection: How Contact Forms Get Abused for Spam

26 ตุลาคม 2026อ่าน 8 นาทีการส่งอีเมลให้ถึงผู้รับ
Email Header Injection: How Contact Forms Get Abused for Spam

Short answer: E-mail header injection is an attack in which someone types line breaks and extra header lines into a form field, such as the name, e-mail or subject, so that the code behind the form adds hidden recipients to the message. Your server then sends the attacker’s spam in your name. The fix is to reject line breaks in anything that goes into a header, validate input on the server, use a fixed sender address and limit how often the form can be used.

What an e-mail header is

Every e-mail consists of two parts: headers and a body. The body is the message that people read. The headers are lines of text above it that tell mail systems what to do: who the message is from, who it is for, what the subject is and which address to use for replies. Each header sits on its own line, and a line break marks where one header ends and the next begins.

That small detail is what the attack depends on. If a program builds the headers by putting text from a form straight into them, then a line break typed by a visitor is read as the end of the header and the start of a new one. The program thinks it is writing one header, while the mail system sees two.

How the attack works

Consider a simple contact form that sends you an e-mail. The visitor types a name, an e-mail address and a message. The code puts the address into the Reply-To header so that you can answer with one click. A normal visitor types an address and everything works.

An attacker types an address followed by a line break and then something that looks like another header, for example a Bcc line with a long list of recipients. If the form does not check for line breaks, the finished message carries that Bcc header, and the mail server dutifully delivers a copy to everyone on the list. The attacker can also change the subject, add a new body or override the sender. Bots do this automatically at huge scale, testing thousands of forms to find those that allow it.

The attack is related to other injection problems in which untrusted input is treated as instructions. If you have read about command injection, the idea will be familiar: data crosses a boundary and becomes code.

Why it matters for your business

You may think that a form sending a few extra messages is a small matter. In practice the harm adds up.

Signs that a form is being abused

The first sign is often indirect. You notice a spike in bounce messages for mail you never sent, a warning from the host about outgoing volume, or customers saying that your e-mails are going to spam. Other clues are worth checking:

How to protect your forms

Good protection is layered, because no single check catches everything. The most important rules are simple.

Never put raw input into a header

Treat anything the visitor types as untrusted. Reject or remove carriage return and line feed characters in every value that is used in a header: name, e-mail, subject and anything else. Put free text only in the body of the message, where line breaks are harmless.

Validate the e-mail address properly

Use a proper validation function on the server, not just a pattern in the browser. A valid address never contains a line break. Browser checks can be skipped completely by a bot that sends requests directly.

Use a fixed From address on your own domain

Send the message from an address you control, such as a general website address on your domain, and put the visitor’s address only in the Reply-To header after validating it. This is also the better setup for deliverability, as explained in contact form e-mails from your own domain and the Reply-To header.

Use current libraries and plugins

Established mail libraries and form plugins reject line breaks in headers by default. Old, home-made scripts that call the basic mail function directly are the most vulnerable. If your form is a custom script written years ago, have it checked or replaced, and keep form plugins updated.

Limit how the form can be used

Add a rate limit, a hidden honeypot field or a challenge to slow bots down. Our article on contact form spam protection compares the options. Forms that send a confirmation to the address typed by the visitor can also be abused to send unwanted messages to third parties, which is described in subscription bombing.

Send through authenticated SMTP

Sending through a proper mail account with authentication, instead of a loose local mail function, gives you logs, limits and better reputation. See SMTP relay vs direct sending for the trade-offs.

What to do if you were already abused

If you suspect that the form was used, first disable it or put a simple holding message in its place. Look at the mail queue and the logs to confirm what was sent, and clear the queued spam so it does not continue to leave the server. Fix the vulnerability before you enable the form again, otherwise the attack resumes within minutes.

Then check your reputation. Look for your IP address and domain on blocklists, and ask for removal after the cause is fixed. Make sure that SPF, DKIM and DMARC are in place so that your genuine mail is recognised, and tell your host what happened if they sent a warning. If the abuse came through a hijacked mailbox and not a form, the steps in compromised e-mail account sending spam apply as well.

A short test you can do

If you maintain a form yourself and are comfortable with simple tests, try submitting a harmless value with a line break in the name field on a test copy of the site, and see whether the message that arrives has extra headers. Do this only on your own site and preferably on a staging copy. If the line break reaches the headers, the form needs fixing. If you are not comfortable testing, ask your developer to confirm in writing that header values are sanitised.

How Site AI Audit helps

Site AI Audit does not test your forms for injection and cannot see inside your mail scripts. It checks the e-mail records that protect your domain: SPF and its lookup limit, DKIM signatures, DMARC policy and MX records, each with a plain-language fix. These records do not stop abuse of a form, but a DMARC policy and valid SPF and DKIM help receiving servers recognise your genuine mail and spot messages that pretend to come from you. The Monitor plan repeats the check every week and sends e-mail alerts when something breaks. You can run a free check of your website or see the plans.

Related reading

The bottom line

Treat every form field as untrusted. Reject line breaks wherever input reaches an e-mail header, send from a fixed address on your own domain, validate on the server and limit how often a form can be used. A few minutes of care protect you from the much longer job of repairing a damaged sender reputation.

FAQ

Can a contact form really send spam to other people?

Yes, if the code behind it lets visitors add header lines. The message is then delivered to recipients chosen by the attacker, using your server and often your domain.

Does a CAPTCHA stop header injection?

It slows bots but does not fix the underlying flaw. A determined attacker may still get through, so the form must also sanitise input on the server.

Are WordPress form plugins affected?

Well-maintained plugins protect against it by default. Old plugins, custom code and modified themes are the real concern, so keep them updated.

How do I know if my domain was used to send spam through a form?

Look for unexpected bounce messages, a large mail queue, a warning from your host or a blocklist listing. The full headers of a sent message show unusual recipients.

Should I send form e-mails from the visitor’s address?

No. Send from an address on your own domain and place the visitor’s address in Reply-To. Sending in someone else’s name breaks authentication and invites problems.

#Email Security#Web vulnerabilities#Website security
ตรวจเว็บไซต์ของคุณเอง — ฟรีเว็บไซต์ของคุณต้องแก้อะไร — และควรเริ่มตรงไหน
เริ่มใช้ฟรี

เพิ่มเติมจากบล็อก

บทความทั้งหมด →
Internet Solutions

ผลงานอื่นจากทีมเรา

สร้างโดย Internet Solutions ลองผลิตภัณฑ์อื่น ๆ ของเรา — แต่ละตัวช่วยประหยัดเวลาให้คุณในแบบที่ต่างกัน

internet-solutions.net ↗
01โพสต์โซเชียลมีเดียอัตโนมัติ
PostRSS

โพสต์ใหม่จากฟีด RSS ของคุณจะถูกส่งไปยัง Facebook, X, LinkedIn, Telegram และอีก 60+ เครือข่ายโดยอัตโนมัติ

แพ็กเกจฟรี · ตั้งแต่ 2014เยี่ยมชม →
02แชทสด AI สำหรับเว็บไซต์
Talkmio

เว็บไซต์ของคุณตอบผู้เยี่ยมชมตลอด 24/7 จากเนื้อหาของคุณเอง ในภาษาของพวกเขา

แพ็กเกจฟรี · ไม่ต้องใช้บัตรเยี่ยมชม →
03ผู้ช่วย AI
Ask Mio

แชท เขียนโค้ด ออกแบบ เขียนงาน และค้นคว้า Mio เลือกโมเดลที่ดีที่สุดให้แต่ละงาน

แพ็กเกจฟรีเยี่ยมชม →
04ออโต้ไพลอต AI สำหรับบล็อกและโซเชียล
AI Blog Autopilot

AI เขียนบทความ SEO ยาว 2,000–3,000 คำ และแชร์แต่ละบทความไปยังโซเชียลเน็ตเวิร์ก 60 แห่ง

3 บทความแรกฟรีเยี่ยมชม →
05ครอว์ล SEO เชิงลึก
Site SEO AI Audit

ครอว์ล SEO เต็มรูปแบบใน 7 ด้าน รวมถึงการมองเห็นในการค้นหาด้วย AI พร้อมวิธีแก้ที่เรียงตามผลกระทบ

ตรวจครั้งแรกฟรีเยี่ยมชม →
06ฟีด RSS และฟีดสินค้า
RSS Feed Creator

สร้าง RSS จากหน้าเว็บใดก็ได้ พร้อมฟีดสินค้าสำหรับ Google และ Meta ที่อัปเดตตัวเองได้

แพ็กเกจฟรีเยี่ยมชม →
07พัฒนาเว็บไซต์และ SEO
Internet Solutions

เว็บไซต์ ร้านค้าออนไลน์ และระบบเฉพาะทาง ออกแบบ สร้าง และดูแลโดยทีมของเรา

ตั้งแต่ 2011เยี่ยมชม →