Start New Discussion Reply to this Discussion Email form make the fields array
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.
Related Article: PHP/HTML Contact Email Form
is a solved PHP discussion thread by Red Dragon that has 2 replies, was last updated 1 year ago and has been tagged with the keywords: contact, php, email, form.
dany12
Posting Whiz in Training
223 posts since Aug 2010
Reputation Points: 21
Solved Threads: 15
Skill Endorsements: 1
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);
priebd1
Newbie Poster
8 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Thank you for this ,can you tell why is not a good pratice to put the fields in an array?
dany12
Posting Whiz in Training
223 posts since Aug 2010
Reputation Points: 21
Solved Threads: 15
Skill Endorsements: 1
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.
priebd1
Newbie Poster
8 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
© 2013 DaniWeb® LLC
Page generated in 0.0740 seconds
using 2.73MB