PHP_USER1
PHP_USER1

Reputation: 628

want to send a mail from my server

      <?php
      $email2=$_POST['mail'];
      $subject2 = "Information about the user";
      $message2= "name=    " .$_POST['name']."<br>". 
                 "      phone=    ".$_POST['phone']."<br>".
                 "     email=   ".$_POST['mail'];
      $from2 = "[email protected]";
      $headers2 = "From:" . $from2; 
      mail($email2, $subject2,$message2, $headers2 );    
      ?>

I want to send the mail from my server . but my problem is NAME , PHONE and EMAIL IS COMING IN SAME LINE . I WANT LIKE THIS -:

NAME =

EMAIL =

PHONE =

HOW TO EDIT THE MESSAGE PART

Upvotes: 0

Views: 61

Answers (2)

S&#233;bastien
S&#233;bastien

Reputation: 12139

<br> will be rendered as plain text unless you send your mail as text/html which is not what PHP's mail function will do by default, so you need to output newlines (\n).

Change the message part like this:

$message2 = 'name: '.$_POST['name']."\n";
$message2 .= 'phone: '.$_POST['phone']."\n"; 
$message2 .= 'email: '.$_POST['email']."\n";

You could read this as a starting point to secure your script against PHP mail header injections.

Upvotes: 2

Adam D. Ruppe
Adam D. Ruppe

Reputation: 25595

PHP's mail function sends plain text (unless you set all the needed headers), so you should use "\n" instead of "<br>".

Upvotes: 2

Related Questions