Jump to content

email script help - writting to csv file


grk101

Recommended Posts

Hello,  Newbie on this forum.. i have done a search, and come up with the follow script, but for some reason i can not get my php email script to write to the cvs file..

 

Well i can take " name , etc " to pass, but now the values that are entered.

 

I would appreciate any help..

 

Also is there a way to make this script, so only people on that domain can use it?

 

Much appreciated.

 

<?php session_start();?>
<?




$to = "test@test.com";


if (!isset($_POST['submit'])) {

  showForm();

} else { //form submitted

  $error = 0;


  if(empty($_POST['imagetext'])) {
    $error = 1;
    $errstr[] = "Please validate the image code";
  } else {
    include "securimage.php";
    $img = new Securimage();
    $valid = $img->check($_POST['imagetext']);

    if(!$valid) {
      $error = 1;
      $errstr[] = "The code you entered was incorrect";
    } 
  }

  if ($error == 1) {
    echo "<center>\n<font style=\"color: #FF0000\">\n";
    foreach($errstr as $err) {
      echo "<li> " . $err . "</li>\n";
    }
    echo "</font>\n</center>\n<br />\n\n";

    showForm();

  } else {
    @mail($to, "Site Contact - " . $_POST['bname'],
    "Add a Site,\n " . date("r") . ", " . $_POST['name'] . " " . $_POST['email'] .  
 "\n\n Name:\n" . $_POST['name'] .
 "\n\n Phone:\n" . $_POST['phone'] .
  "\n\n Comments:\n" . $_POST['comments'] .
       "\n\n" . stripslashes($_POST['']), "From: " . $_POST['email']);



$file_name = "test.csv";
$first_raw = "name,phone,email,comments\r\n";
$values = "name,phone,email,".str_replace ("\r\n","<BR>",comments )."\r\n";
$is_first_row = false;
if(!file_exists($file_name))
{
$is_first_row = true ;
}
if (!$handle = fopen($file_name, 'a+')) {
die("Cannot open file ($file_name)");
exit;
}
if ($is_first_row)
{
  if (fwrite($handle, $first_raw ) === FALSE) {
  die("Cannot write to file ($filename)");
  exit;
  }
}
if (fwrite($handle, $values) === FALSE) {
  die("Cannot write to file ($filename)");
  exit;
}
fclose($handle);

    echo "<center><font color=black>\nThank You.  
          </font> <br /><br />"
        ."<font color=white>Click <a href=\"#\" onclick=\"self.close()\">here</a> to close this window.</font>";

  }

} //else submitted



function showForm()
{


  echo <<<EOD
             
  		
<form method="POST" class="cssform">


<br />
<br />



<hr/>
<br />

<p><label for="name" class="required">*Name:</label>
<input type="text" id="name" name="name" size="27" value="{$_POST['name']}"/></p>

<p><label for="email" class="required">*Email:</label>
<input type="text" id="email" name="email" size="27" value="{$_POST['email']}"/></p>

<p><label for="phone" class="required">*Phone:</label>
<input type="text" id="phone" name="phone" size="27" value="{$_POST['phone']}"/></p><br />

<p><label for="Comments">Comments:</label>
<input type="text" id="comments" size="27" name="comments" /></p>





<span class="table2">
*Type the characters:                
<input name="imagetext" type="text" size="5" />
<img src="securimage_show.php">
</span><br />

<br />
<hr/>
<br />
<div style="margin-left: 25px;">
<input type="submit" class="formbutton" value="Submit" name="submit"/>       
<input type="reset" class="formbutton" value="Clear Form" />
</div>
</form>


EOD;
}

?>

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.