Hi,
I'm totally new to HTML, PHP and Javascript (only started learning a couple of days ago).
I've set up a simple website (http://start10g.ovh.net/~ibnoobs/) which contains links to resources for students doing the IB diploma.
What I need help with is a simple "Submit a link" form which I have already set up. My problem is that I don't know how to include more than 1 field into the body of the email that is sent to me when a person submits a link. I would ideally like to have a form containing 6 fields (see http://start10g.ovh.net/~ibnoobs/submit.php) one of them being a choice between 3 radio buttons.
The form is set up in 2 pages, one containing the actual form and the other the code that mails the form. So how do I get the data from all 6 fields into the body of the email.
Here is the code for my two pages:
form page:
<!Doctype: php>
<head>
<title>Submit a link</title>
</head>
<body>
<?php include 'template.html' ; ?>
<h3> Submit a link to IBnoobs.com </h3>
<form method="post" action="sendmail.php">
Your name:<br />
<input type="text" name="name" size="25">
<br />Your e-mail adress:
<br /><input type="text" name="email" size="25">
<br />Link you wish to submit:
<br /><input type="text" name="link" size="40">
<br />Subject(s) to which the link is relevant
<br /><input type="text" name="link" size="40">
<br /><input type="radio" name="level" value="HL">HL
<br /><input type="radio" name="level" value="SL">SL
<br /><input type="radio" name="level" value="Both">Both
<br />Short descripton of link (optional):
<br /><input type="text" name="description" size="40">
<br /><br />
<input type="submit" />
<br />
<br />
<br />
<?php include 'footer.html' ; ?>
</form>
</body>
</php>
send mail page:
<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['level'] ;
mail( "postmaster@ibnoobs.com", "Reported Link",
$message, "From: $email" );
header( "Location: ./thankyou.html" );
?>
Thanks in advance.
Noob needs help with form sent to email
Moderator: General Moderators
Re: Noob needs help with form sent to email
For the very basics, try replacing
with
Code: Select all
$email = $_REQUEST['email'] ;
$message = $_REQUEST['level'] ;Code: Select all
$email = $_POST['email'];
$message = $_POST['name'] . "<br />" . $_POST['link'] . "<br />" . $_POST['level'] . "<br />" . $_POST['description'];Re: Noob needs help with form sent to email
That doesn't seem to work... I get this error when I submit the form:
"Parse error: syntax error, unexpected '=' in /home.42/i/b/n/ibnoobs/www/sendmail.php on line 2"
"Parse error: syntax error, unexpected '=' in /home.42/i/b/n/ibnoobs/www/sendmail.php on line 2"
Re: Noob needs help with form sent to email
Hi, I have a code you can perhaps modify?
The original form I have is published on but this is only a one page form, if it's of interest to you let me know?
Mike
The original form I have is published on but this is only a one page form, if it's of interest to you let me know?
Mike
Last edited by mikes1471 on Sun Feb 01, 2009 1:01 pm, edited 1 time in total.
Re: Noob needs help with form sent to email
Hi Mike,mikes1471 wrote:Hi, I have a code you can perhaps modify?
The original form I have is published on http://www.picfrisky.com/contact.html but this is only a one page form, if it's of interest to you let me know?
Mike
My form will only be one page as well, so I might have a chance to modify yours to work for me.
So yeah, I am interested to see it.
Re: Noob needs help with form sent to email
No problem, this is the first document which I saved and uploaded to my server as 'contactformprocess.php'
And this code is to be entered into the body of your contact page:
This is literally help from one noob to another so any problems I can try to help but it works perfectly for me
Code: Select all
<?php
// get posted data
$Email = Trim(stripslashes($_POST['Email']));
$EmailTo = "(Place your email here)";
$Subject = "(Email subject here)";
$Name = Trim(stripslashes($_POST['Name']));
$Subject = Trim(stripslashes($_POST['Subject']));
$Comments = Trim(stripslashes($_POST['Comments']));
$Newsletter = Trim(stripslashes($_POST['Newsletter']));
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Subject: ";
$Body .= $Subject;
$Body .= "\n";
$Body .= "Comments: ";
$Body .= $Comments;
$Body .= "\n";
$Body .= "Newsletter: ";
$Body .= $Newsletter;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$Email>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>Code: Select all
<form method="POST" action="contactformprocess.php">
<p> From (your Email address):* <br>
<input name="Email" type="text" maxlength="50">
<p>Name:* <br>
<input name="Name" type="text" maxlength="50">
<p>Subject:* <br>
<input name="Subject" type="text" maxlength="50">
<p>Comments:* <br>
<textarea name="Comments" cols="40" rows="5"></textarea>
<p>Subscribe to Newsletter:
<input type="checkbox" name="Newsletter">
<p><input name="submit" type="submit" onclick="MM_validateForm('Email','','RisEmail','Name','','R','Subject','','R','Comments','','R');return document.MM_returnValue" value="Submit">
<br><br>
<span class="style2">Fields marked (*) are required</span>
</form>