Jump to content

Script error when I try to use it in a webpage


LuciBKen

Recommended Posts

Hi there,

 

I seem to be having a problem getting my script to work on a webpage, when the page loads, it shows the box to enter an email address and the submit button, but when an address is entered (valid or invalid) and the button is clicked, there is no action except for what looks like the form reloading.

 

Here is the script and I have placed it in the HTML right before the <BODY> close tag.

 

Could someone please let me know what I'm doin wrong?

 

<?php

# ----------------------------------------------------

# ----- Designed by: Richard Kellermeyer, Luci Publishing Group, Inc.

# ----- http://www.lucipublishing.com

# ----------------------------------------------------

 

 

// Receiving variables

@$email = addslashes($_POST['email']);

 

// Validation

if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))

{

die("<p align='center'><font face='Arial' size='3' color='#FFFFFF'>That email address is invalid</font></p>");

}

 

if (strlen($email) == 0 )

{

die("<p align=\"center\"><font face=\"Vrinda\" size=\"4\"color=\"#FFFFFF\">Please enter your email address</font></p>");

}

 

//Sending auto respond Email to user

# Email to Owner

$pfw_header = "From: *******@*******.com";

$pfw_subject = "Comfirmation";

$pfw_email_to = "$email";

$pfw_message = "Email Confirmation";

@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

 

//saving record in a csv file

$pfw_file_name = "emails.csv";

$pfw_first_raw = "email\r\n";

$pfw_values = "$email\r\n";

$pfw_is_first_row = false;

if(!file_exists($pfw_file_name))

{

$pfw_is_first_row = true ;

}

if (!$pfw_handle = fopen($pfw_file_name, 'a+')) {

die("Cannot open file ($pfw_file_name)");

exit;

}

if ($pfw_is_first_row)

{

  if (fwrite($pfw_handle, $pfw_first_raw ) === FALSE) {

  die("Cannot write to file ($pfw_filename)");

  exit;

  }

}

if (fwrite($pfw_handle, $pfw_values) === FALSE) {

  die("Cannot write to file ($pfw_filename)");

  exit;

}

fclose($pfw_handle);

 

//Storing address in database

 

$dbhost = '******';

$dbuser = '******';

$dbpass = '******';

 

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die

('Error connecting to mysql');

 

$dbname = 'testemail';

mysql_select_db($dbname);

 

$sql = "insert into email (email_address) values('$email')";

mysql_close($conn);

 

echo("<p align='center'><font face='Arial' size='3' color='#FFFFFF'>An email has been sent with a link to your free

 

item.</font></p>");

include("footer.html");

 

?>

 

What this script is intended to do is gather the entered email address, check it for validity, send it to a .csv file, send it to a database then send a response email back to the email address that was entered.

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.