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 = "[email protected]"; $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? Link to comment https://forums.phpfreaks.com/topic/190170-contact-form-output-to-page-and-email/ 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 Link to comment https://forums.phpfreaks.com/topic/190170-contact-form-output-to-page-and-email/#findComment-1003339 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... Link to comment https://forums.phpfreaks.com/topic/190170-contact-form-output-to-page-and-email/#findComment-1003343 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. Link to comment https://forums.phpfreaks.com/topic/190170-contact-form-output-to-page-and-email/#findComment-1003344 Share on other sites More sharing options...
teamatomic Posted January 29, 2010 Share Posted January 29, 2010 push them to an array ie. $array[[email protected]] then do your content with a foreach $content.= "\n$key: $value"; HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/190170-contact-form-output-to-page-and-email/#findComment-1003374 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.