Jump to content

How can i add form fields to a sendmail file?


michaelpalmer7

Recommended Posts

Hi there i'm new to php but am learning fast, i ammaking a website with a contact us page with a form with subject, message, surname, email etc.    I have a endmail.php file that e-mails the e-mail address and message but i want to add the other fields so it will e-mail them i.e. surname etc.  here is my curent script:   

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

  mail( "yourname@example.com", "Feedback Form Results",
    $message, "From: $email" );
  header( "Location: http://thankyou.htm" );
?>

Any help would be greatly appreciated,
Cheers....
Link to comment
Share on other sites

Not entirely sure what you're after here Michael!

You want them to enter their surname, address etc. and have it displayed along the message in the email you receive?

The key to this is $message. That's basically what you get sent. At the moment, the user puts their message in $message, and it gets sent - as is - to you. What we're gonna need to do is change it before sending it.


Something like this:

$newmessage = "Name: $name
Contact Email: $contactemail
Address: $address
Other Value1: $othervalue
Other value2: $othervalue


Customer's Message:

". $message;


Adding these lines to your existing script should do the trick. In this example, $name, $contactemail, $address, $othervalue1, $othervalue2 are all values passed by your form.


PS: You shouldn't have to do "$email = $_REQUEST['email'];" for your values? Should work without. Try it. If you do need to do this for values, you'll need to do it for the new ones too.
Link to comment
Share on other sites

Forgot to mention, you'd need to change the 'message' value you're sending to the mail() function to $newmessage, from $message.

PS: If you don't get this I can show the whole edited script for ya, just ask. This way though I'm trying to show ya why the changes work and what's been done. Easy to understand - just the value you pass in that mail() function where $message is should be changed to whatever you want yourself to be sent. :)
Link to comment
Share on other sites

thanks for the reply

i tried adding the script and changing it slightly, but i was getting bombarded by parse errors etc.
it would be a great help if you could write the script, i think i'm a bit too new to this, the fields are named:
subject,mesage,title, firstname,surname,telephone and email. and you were right i just want them to appear on the email i recieve, heres my sendmail.php script again 

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

  mail( "yourname@example.com", "Feedback Form Results",
    $message, "From: $email" );
  header( "Location: http://thankyou.htm" );
?>

any help would be greatly appreciated,
cheers
Link to comment
Share on other sites

<?

$newmessage1 = "Customer Contact Form Results.

Subject: $subject
Full Name: $title $firstname $secondname
Telephone: $telephone
Email Address: $email

Message Body:

$message";


  mail( "yourname@example.com", "Feedback Form: " . $subject,
    $newmessage1, "From: $email" );
  header( "Location: http://thankyou.htm" );
?>

any help would be greatly appreciated,
cheers

[/quote]


That should do the trick, the subject chosen will appear in the email subject as well as an added touch, lol.

It's pretty important that you understand what I did though - the message we send is simply this variable in your code - the one I've highlighted:

mail( "yourname@example.com", "Feedback Form Results",
    [b]$message[/b], "From: $email" );

- I  renamed it but it doesn't make a difference. Whatever $message is (or $newmessage, now I changed it) is what gets sent. It's a variable like any other, so I simply made it like any other. :)
Link to comment
Share on other sites

hi me again still struggling

this is my sendmail script now:

<?

$newmessage1 = "Customer Contact Form Results.

Subject: $subject
Full Name: $title $firstname $surname
Telephone: $telephone
Email Address: $email

Message Body:

$message";


  mail( "yourname@example.com", "Feedback Form: " . $subject,
    $newmessage1, "From: $email" );
  header( "Location:  http:thankyou.htm" );
?>

I put it online with my e-mail and thankyou page etc. and when i pressed submit it said:

Notice: Undefined variable: subject in sendmail.php on line 6

Notice: Undefined variable: title in sendmail.php on line 6

Notice: Undefined variable: firstname in sendmail.php on line 6

Notice: Undefined variable: surname in sendmail.php on line 7

Notice: Undefined variable: telephone in sendmail.php on line 8

Notice: Undefined variable: email in sendmail.php on line 10

Notice: Undefined variable: message in sendmail.php on line 12

Notice: Undefined variable: subject in sendmail.php on line 15

Notice: Undefined variable: email in sendmail.php on line 16

Warning: Cannot modify header information - headers already sent by (output started at sendmail.php:6) in sendmail.php on line 17

i have tried changing a bit since but no luck  please help if you can
Link to comment
Share on other sites

Hmm, seems that in your environment/form method you do need to use these things:
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message']

Do that for all of the variables, and put the lines at or near the top of the script. See if that helps.

The header warning... I'm not entirely sure.
This redirect is definitely causing the problem:
[i]header( "Location:  http:thankyou.htm" );[/i]

And the problem is that this is a header based redirect, so it can't happen after even a single line of html has been passed. However, I don't know why it thinks some has. Possibly changing the first thing would help here - I don't know.

Add those extended variable definitions and post back.
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.