# My PHP contact form sends a blank email when someone submits it

Source: https://coursesweb.net/forum/t/my-php-contact-form-sends-a-blank-email-when-someone-submits-it/
Site: CoursesWeb Forum, category PHP Forms, Sessions and Basics
Published: 2026-11-27. Updated: 2026-11-27. Replies: 1.

## Question by Lin W., 2026-11-27

I keep a small ordering page alive for my family's restaurant and I added a contact form to it last night. When I fill it in and press Send, the email arrives, but the body is empty. It only says "Name: " and "Message: " with nothing after.

This is the form:

```html
<form method="post" action="contact.php">
  <input type="text" id="name">
  <textarea id="message"></textarea>
  <button type="submit">Send</button>
</form>
```

And contact.php:

```php
<?php
$name = $_POST['name'];
$message = $_POST['message'];
mail('orders@example.com', 'Contact form',
     "Name: $name\nMessage: $message", 'From: web@example.com');
```

The page does not show any error on the screen. Our host writes a log file though, and it says:

`PHP Warning:  Undefined array key "name" in /home/site/contact.php on line 2`

The same warning appears for "message". I am scared of changing too much because the ordering page shares the same folder. What does the warning mean and why is the data not arriving?

## Reply 1 by Ewa P., 2026-11-27

Look at your HTML, the inputs have an id but no name attribute. The browser only sends fields that have a name, so PHP never receives them. Add name="name" and name="message" and try again.

I would also stop using the raw values in the email headers later on. For now the body is fine.

---
Cite as: CoursesWeb Forum, "My PHP contact form sends a blank email when someone submits it", https://coursesweb.net/forum/t/my-php-contact-form-sends-a-blank-email-when-someone-submits-it/, accessed 2026-11-27.
