# Help Formatting PHP Email (And other little various issues)

**URL:** <https://forum.kirupa.com/t/help-formatting-php-email-and-other-little-various-issues/266039>\
**Category:** programming\
**Created:** [July 15, 2008, 6:55pm UTC](https://forum.kirupa.com/t/help-formatting-php-email-and-other-little-various-issues/266039 "2008-07-15T18:55:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sosADAMsos](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@sosADAMsos](https://forum.kirupa.com/u/sosADAMsos)\
**Post date:** [July 15, 2008, 6:55pm UTC](https://forum.kirupa.com/t/help-formatting-php-email-and-other-little-various-issues/266039/1 "2008-07-15T18:55:13Z")

</div>

I’ve read many posts and done tons of searching/testing but just cant seem to figure it out:

I’m trying to create a simple php form for my website.

I’m making the first one simple and just asking for name, email, and comments.

The PHP I’m currently using is

```php

<?php
if(isset($_POST['submit'])) {

    $subject = "Contact Form";
    $name_field = $_POST['name'];
    $email_field = $_POST['email'];
    $comments_field = $_POST['comments'];
    $from = 'From: '.$name_field."
";    
    $to = "adam@XXXXX.com";
    
    $body = "From: $name_field
 E-Mail: $email_field
 Comments: $comments_field";

    mail($to, $subject, $body, $from);
    
}
?> 

```

That’s sending me this email (to which I’ve made revisions):  
 ![](http://www.fwhittier.com/upload/form1.gif)

1. Why is the top text “email” and “comments” being indented?

2. How can I add a message below? I’ve tried fooling around with $msg = “yada yada yada”, but I can’t seem to get it.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [July 15, 2008, 7:31pm UTC](https://forum.kirupa.com/t/help-formatting-php-email-and-other-little-various-issues/266039/2 "2008-07-15T19:31:21Z")

</div>

```php

"From: $name_field
 E-Mail: $email_field
 Comments: $comments_field"; 

```

While this is syntax-wise ‘correct’, I’d suggest doing this instead

```php

"From: " . $name_field . "
 E-Mail:" . $email_field . "
 Comments:" . $comments_field; 

```

---

<div class="post-metadata">

**Author:** ![sosADAMsos](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@sosADAMsos](https://forum.kirupa.com/u/sosADAMsos)\
**Post date:** [July 15, 2008, 8:25pm UTC](https://forum.kirupa.com/t/help-formatting-php-email-and-other-little-various-issues/266039/3 "2008-07-15T20:25:32Z")

</div>

Why is that? Is it more secure?

---

<div class="post-metadata">

**Author:** ![sosADAMsos](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@sosADAMsos](https://forum.kirupa.com/u/sosADAMsos)\
**Post date:** [July 15, 2008, 8:51pm UTC](https://forum.kirupa.com/t/help-formatting-php-email-and-other-little-various-issues/266039/4 "2008-07-15T20:51:47Z")

</div>

Okay… I used an approach similar to yours and have something that will work for me:

```php

<?php
if(isset($_POST['submit'])) {

    $subject = "CONACT MESSAGE FROM XXXXX";
    $from = 'From: ' . $_POST["name"] . "
";    
    $to = "adam@XXXXX.com";
    
	$message = "Contact Message From XXXXX" . "

";
    $message .= "Name:
" . $_POST["name"] . "

";
	$message .= "Email:
" . $_POST["email"] ."

";
	$message .= "Comments:
". $_POST["comments"];

    mail($to, $subject, $message, $from);
    
}
?>

```

But I have a few questions:

1. Is this form secure / could it be taken advantage of? (I know it would get spam, but could it be hacked?)

2. Whats the difference between just a “  
” and a “  
”?

3. Is there anything I should do to better this form?
