Jump to content

simple form to write to a txt file and email out


samoht

Recommended Posts

Hello all,

 

I am trying to make a simple php form that only has two fields and a submit button. I would like two things to happen when the user hits submit:

[*]submission to a text file in the same directory with name, email, date and time submitted

[*]send email to me and copy to user

 

Any Ideas how to do this??

 

Thanks

 

here is the simple form:

<form action="rsvp.php" method="get" name="accept_form" id="accept_form" class="form">

<p>Name:</p>

<input class="cf_inputbox required" maxlength="150" size="30" id="name" name="name" type="text">

 

<p>Email:</p>

<input class="cf_inputbox required validate-email" maxlength="150" size="30" id="email" name="email" type="text">

 

<input value="Submit" name="undefined" type="submit">

 

<input type="hidden" name="ea877a395200687bacc18620f1fc610e" value="1" />

 

</form>

[/[code=php:0]

 

Yes, thanks for that.

 

but I am getting a:

Warning: fopen(data.txt) [function.fopen]: failed to open stream: Permission denied in /var/www/oldcastleglass/enews/emails/rsvp.php on line 9

Error, the file could not be opened or there was an error creating it.

 

here is my code:

<?php

if (isset($_POST['undefined'])) {

$name = $_POST['name'];
$email = $_POST['email'];
$date = date("F j, Y, g:i a"); 

$fp = fopen("data.txt","a");

if(!$fp) {
    echo 'Error, the file could not be opened or there was an error creating it.';
    exit;
}
fwrite($fp, "\n" .$name. " has accepted the invitation\nemail=". $email. "\nSubmision was made ". $date. "\n");

fclose($fp);

// multiple recipients
$to  = '[email protected]' . ', '; // note the comma
$to .= '[email protected]';

// subject
$subject = 'RSVP for SFMOMA Event Confirmation';

// message
$message = '
<html>
<head>
  <title>RSVP for SFMOMA Event Confirmation</title>
</head>
<body>
<p>This email is to confirm ';
$message .= $name;
$message .= ' for the SFMOMA Event. </p><p>Email = ';
$message .= $email;
$message .= '</p><p> Submision was made on:';
$message .= $date;
$message .= '
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
//$headers .= 'To: '.$name.' <'. $email.'>' . "\r\n";  //this is the line to comment out if you dont want to send to the user!!
$headers .= 'From: Web Confirmation <[email protected]>' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);

}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>RSVP Form</title>
  <script type="text/javascript" src="mootools.js"></script>

</head>

<body>

<div class="outter">
<div class="logo"><a href="http://oldcastleglass.com"><img src="images/oglogo.jpg" alt="Oldcastle Glass" border="0" /></a></div>
<div class="main">
<h1>RSVP for SFMOMA Event</h1>
<p>Please enter your name and email address below and click 'Submit' <br />
  to confirm your attendance.</p>


<script src="mooValidation.js" type="text/javascript"></script>

<form action="<?php echo $_SERVER['SCRIPT_NAME']?>" method="post" name="accept_form" id="accept_form" class="form">
<div class="form_item">
<div class="form_element cf_textbox">
	<p>Name:</p>
	<input class="cf_inputbox required" maxlength="150" size="30" id="name" name="name" type="text">
</div>
<div class="clear"> </div>
</div>
<div class="form_item">
<div class="form_element cf_textbox">
	<p>Email:</p>
	<input class="cf_inputbox required validate-email" maxlength="150" size="30" id="email" name="email" type="text">
</div>
<div class="clear"> </div>

</div>
<div class="form_item">
<div class="form_element cf_button">
	<input value="Submit" name="undefined" type="submit">
</div>
<div class="clear"> </div>
</div>		
<input type="hidden" name="ea877a395200687bacc18620f1fc610e" value="1" />	

</form>
<script type="text/javascript">
function formCallback(result, form) {
	window.status = "valiation callback for form '" + form.id + "': result = " + result;
}
var valid = new Validation('accept_form', {immediate : true, useTitles : true, onFormValidate : formCallback});
</script>
</div>
<div class="privacy">
  <p> Copyright © 2009 I  1-866-OLDCASTLE (653-2278) I  All Rights Reserved I <a href="../../privacy.php">Privacy Policy</a> <br />
  </p>
</div>
</div>
</body>
</html>

is there a text file there already? if so get info on it in your ftp problem and change the group perm to read/write. if not then get info on the directory and change the group perm to read/write.

 

this should work but may depend on what user PHP executes as.

If it is created in a directory, set the permissions (chmod) to 0777 or 777.

 

Just backing up schilly's information a bit there :P

 

thanks. i knew what to do but couldn't remember all the quirks about file perms and which codes were which.

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.