Hello
I was wondering how to create an array with all fields in a email form and then send the email

<?php
if(isset($_POST['submit']))//array{
            $content=array(
            $name=strip_tags($_POST['name']);
            $email=strip_tags($_POST['email']);
            $phone=strip_tags($_POST['phone']);
            $address=strip_tags($_POST['address']);
            $city=strip_tags($_POST['city']);
            $title=strip_tags($_POST['subject']);
            $message=strip_tags($_POST['message']);
            );

            }


             $to = "email@domain.com";
            $subject =$title;
            $from = $name;
            $headers = "From:" . $from;
            mail($to,$subject,$content/*change array to string so that can be sent by email*/ 
            ,$headers);
            echo "Mail Sent.";
            else"Email not send"
            ?>

Thank you in advance.

Don't put all of your content in an array instead do this:

// intialize all of your variables from your form first like you had it..
$name=strip_tags($_POST['name']);
$email=strip_tags($_POST['email']);
$phone=strip_tags($_POST['phone']);
$address=strip_tags($_POST['address']);
$city=strip_tags($_POST['city']);
$title=strip_tags($_POST['subject']);
$message=strip_tags($_POST['message']);

Then set all of them to $content like this:

$content = <<<_START
Name: $name\n Email: $email\n Phone: $phone\n Address: $address\n City: $city\n Title: $title\n Message:$message
_START; // must be on its own line

Then:

mail($to,$subject,$content,$headers);

Thank you for this ,can you tell why is not a good pratice to put the fields in an array?

It really depends on what you want to do with the fields. If you need to sort them alphabetically or numercially then an array is what you should do. But if you just need to mail them to someone then you reall dont need the functionality of arrays.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.