Form emails me on Submission

Status
Not open for further replies.

murdocsvan

Web Programmer
Messages
896
Location
Surrey, UK
Hi, i need to find a way of getting to email me the details when the form has been filled in. I tried the action="MAILTO:blah@blah.com" but it just opened up my email client. I dont want it to do this. I know HTML and CSS, and some PHP, but otherwise i have no idea how to do this. can anyone help meee?
 
You can either do this with HTML or PHP.
Which is your prefered method? :p

(Note that PHP is less "spam friendly" if you like :))

Cheers,

~ Tkey
 
HTML. but if its the <form action="MAILTO: " then i dont want that, because that wont work. im making a website for the in-game browser in EVE online, which has very limited coding capabilities. it supports HTML 3.2, and CSS, and a few others.

thanks
 
PHP:
<?php
$message = $_POST['message'];
mail('youremail@gmail.com', 'Subject', $message);
?>

Thats it in PHP, needs abit of tweeking depending on how and where it is used. If you need any help with using it just post your code.
 
Code:
<form action="MAILTO:planetaliens98@hotmail.com" method="post" enctype="text/plain"> 
				<p>
					Character Name
						<input type="text" name="firstname">
				</p>
				<p>
					First Name IRL 
						<input type="text" name="lastname">
				</p>
				<p>
					Character Race
						<select name="race">
							<option value="gallente">Gallente</option>
							<option value="caldari">Caldari</option>
							<option value="minmitar">Minmitar</option>
							<option value="amarr">Amarr</option>
						</select>
				<p>
					Email
						<input type="text" name="email">
				</p>
				<p>
					<input type="submit" value="Submit">
					<input type="reset" value="Reset">
			</form>

Thats the form im going to use for submission.
 
Change the first line with:

PHP:
<form name="input" action="submit_contact.php" method="post">

With submit_contact.php being :

PHP:
<?php

// Assigning the posted values to variables.
$charactername = $_POST['firstname'];
$nameIRL = $_POST['lastname'];
$race =  $_POST['race'];
$email = $_POST['email'];

// Sending the email with all the info.
mail('planetaliens98@hotmail.com', 'Subject', "First Name: ".$charactername."   Fire Name IRL: ".$nameIRL."   Race: ".$race."   Submitted by: ".$email." ");
?>

Hope i helped.
PS: Thats the basic way, ask me for more help if you need any. If you get that working, ill give you a good code for checking if the email is correct and exists.
 
thanks a lot zedman. i copied the code, but edited it a bit. i was sort of following what you said and what another website said at the same time:

PHP:
<?php
$to = "planetaliens98@hotmail.com";
$subject = "Mail List Application";
$first = $_POST["first_name"];
$character = $_POST["character_name"];
$race = $_POST["race"];
$email = $_POST["email"];
$message = "$first, $character, $race, $email";
$from = "NOREPLY@tom.djfhosting.co.uk";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
?>

that was the code for the PHP page.

and yes i Would like that code for checking the email is correct lol. currently theres no form of validation, and nothing to stop someone from just flooding my inbox.
 
PHP:
function check_email_address($email) {
  // First, we check that there's one @ symbol, 
  // and that the lengths are right.
  if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
    // Email invalid because wrong number of characters 
    // in one section or wrong number of @ symbols.
    return false;
  }
  // Split it into sections to make life easier
  $email_array = explode("@", $email);
  $local_array = explode(".", $email_array[0]);
  for ($i = 0; $i < sizeof($local_array); $i++) {
    if
(!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&
?'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",
$local_array[$i])) {
      return false;
    }
  }
  // Check if domain is IP. If not, 
  // it should be valid domain name
  if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
    $domain_array = explode(".", $email_array[1]);
    if (sizeof($domain_array) < 2) {
        return false; // Not enough parts to domain
    }
    for ($i = 0; $i < sizeof($domain_array); $i++) {
      if
(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|
?([A-Za-z0-9]+))$",
$domain_array[$i])) {
        return false;
      }
    }
  }
  return true;
}

$validemail= check_email_address($_POST['email']);

if ($validemail == false) {
die('Sorry, the email '.$_POST['email'].' is invalid. <a href=previous.php>Click Here to go Back.</a>');
}
 
You can either put it in a functions file (if you use many functions) or you can just leave it in the same page.

That code checks the email, with an if statement at the bottom:

PHP:
if ($validemail == false) {
die('Sorry, the email '.$_POST['email'].' is invalid. <a href=previous.php>Click Here to go Back.</a>');
}

So you can just modify that a little to send the email if it returns true:

PHP:
if ($validemail == false) {
die('Sorry, the email '.$_POST['email'].' is invalid. <a href=previous.php>Click Here to go Back.</a>');
} else {
mail('planetaliens98@hotmail.com', 'Subject', "First Name: ".$charactername."   Fire Name IRL: ".$nameIRL."   Race: ".$race."   Submitted by: ".$email." ");
}
 
Status
Not open for further replies.
Back
Top Bottom