Jump to content

Quick php question regarding contact form


buggedout

Recommended Posts

Hi all

 

I am new with PHP and this simple thing has been driving me nuts. I finally got my contact form to work successfully thanks to tutorials around the internet.

 

But I don't know what code to use so that I may view the name entered in the name field on the form, or have the email displayed how I would like it.

 

Right now when I get the email, the from address is the email the person types in. OK. The message shows up just as an ordinary message without anything else... that works, but what I would like is for the email to arrive in this format:

 

Name: (name)

 

Email: (email address)

 

Message: (message)

 

right now only the message shows up in the email body. I would like to see everything in the email body. the name doesn't show up anywhere.

 

I have tried a few different things but then I get error 500 when I submit the form. I know I am missing something simple.

 

I have attached the code I am using. Wasn't able to copy and paste.

 

Please help!

 

 

 

sendmail.php

Link to comment
Share on other sites

<?php
  $name = $_REQUEST['name'] ;
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;

  mail( "admin@yoursite.com", "Feedback Form Results",
    $message, "From: $email" );
  header( "Location: http://www.yoursite.com/thankyou.html" );
?>

Look at some mail examples from php.net

 

Posting the code from your form could also help.

Link to comment
Share on other sites

You'd have to do something like this:

<?php

$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

$body = sprintf(
    "Name: %s\n\nEmail: %s\n\nMessage: %s",
    $name,
    $email,
    $message
);

mail( "admin@yoursite.com", "Feedback Form Results",
$body, "From: $email" );
header( "Location: http://www.yoursite.com/thankyou.html" );
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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