Jump to content

contact form - output to page and email


Omzy

Recommended Posts

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

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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.