Adding Fields to the Body of a PHP Email

1

The problem is that I have a contact form, it works fine but I need it to contain more fields in the body of the email message.

For example, I have some fields like company, phone, etc ... I would need them in the email body, too.

Let's look at the current situation of CODE PHP

    <?php
    $name       = @trim(stripslashes($_POST['name'])); 
    $from = trim($_POST["email"]);
    $subject    = "Contato via Site"; 
    $message = trim($_POST["message"]);
    $to         = "[email protected]";

    $headers   = array();
    $headers[] = "MIME-Version: 1.0";
    $headers[] = "Content-type: text/plain; charset=iso-8859-1";
    $headers[] = "From: {$name} <{$from}>";
    $headers[] = "Reply-To: <{$from}>";
    $headers[] = "Subject: {$subject}";
    $headers[] = "X-Mailer: PHP/".phpversion();

    $header = implode("\r\n", $headers);
    if (mail($to, $subject, $message, $header)) {

    ?>
        <script language="JavaScript">
        alert("Mensagem enviada.");
        </script>
        <script language='javascript'>history.back()</script>;
        <?
    }

    ?>

Unfortunately, my knowledge of PHP is practically nil.

In short:

I have a contact form, in it is sent only one field in the body of the email, the message. I need to add 3 more fields in the body, Name, Company and Phone.

    
asked by anonymous 11.04.2016 / 17:27

1 answer

2

Only concatenate as Strings :

$message .= $nome . "\n";
$message .= $empresa . "\n";
$message .= $telefone; 
    
11.04.2016 / 17:39