0

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.

Edited by dany12

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by priebd1
0

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);

0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.