Omzy Posted January 28, 2010 Share Posted January 28, 2010 I have the following in my controller: $message['name'] = htmlentities(strip_tags(trim($_POST['name']))); $message['email'] = htmlentities(strip_tags(trim($_POST['email']))); $to = "info@mywebsite.com"; $subject = "Website Enquiry"; $content = html_entity_decode(implode("\n\n", $message)); $content.= "\n\nIP Address: ".$_SERVER['REMOTE_ADDR']; $headers = "From: ".strip_tags(trim($_POST['name']))." <".strip_tags(trim($_POST['email'])).">"; @mail($to,$subject,$content,$headers); And the following in my view: echo '<tr><th><b>Name: </b></th><td>'.$message['name'].'</td></tr>'; echo '<tr><th><b>Email Address: </b></th><td>'.$message['email'].'</td></tr>'; This works as expected - the POST data is output to the page and is also sent in the email. However the email does not contain the field labels, for example 'Name: ' and 'Email Address: '. This is obviously because I don't include the labels in their respective $message[] elements, as I need to enclose these in HTML tags in the view. I don't intend to include any HTML code in my controller, so does anyone have any idea how I can satisfy both requirements? Quote Link to comment Share on other sites More sharing options...
teamatomic Posted January 28, 2010 Share Posted January 28, 2010 $content.= "\n Name: ".$message['name']; $content .= "\n Email: ".$message['email']; HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
Omzy Posted January 28, 2010 Author Share Posted January 28, 2010 Cheers teamatomic. Seems good but I'd rather not do it that way to be honest, the code I provided was a simplified version - my full code has around 15-20 fields and not all are mandatory. So I've got several isset() checks to set the $message elements - these checks would have to be replicated for my $content variable if I use the method you have suggested... Quote Link to comment Share on other sites More sharing options...
Omzy Posted January 28, 2010 Author Share Posted January 28, 2010 Ideally I'd like to specify the labels in my controller and be able to output these in my view. Quote Link to comment Share on other sites More sharing options...
teamatomic Posted January 29, 2010 Share Posted January 29, 2010 push them to an array ie. $array[www@www.ww] then do your content with a foreach $content.= "\n$key: $value"; HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.