Forum Moderators: coopster
Im having a little trouble with a script and was wondering if you guys could help me out,
Ive written an online registration form that sends 12 variables to a page called registration2.php
This form then inserts the info into a mysql database after doing a few checks i.e if the username has already been used or not then (should) send out an email, this is where I get my error.
its a great error aswell.
"
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Apache/2.0.55 (Red Hat) Server at www.example.com Port 80
"
-------------------------------------------------
The server log says
"
malformed header from script. Bad header=/home/sites/example.com/de: registration2.php, referer: http://www.example.com/registration.php
"
Heres the script.
<?php
## include the connection file
include("includes/conn.php");
$forename = $_POST["forename"];
$surname = $_POST["surname"];
$street_address = $_POST["sreet_address"];
$town = $_POST["town"];
$region = $_POST["region"];
$postcode = $_POST["postcode"];
$tel = $_POST["telephone"];
$email = $_POST["email1"];
$username = $_POST["createid"];
$password = $_POST["password1"];
$secret = $_POST["secret_q"];
$answer = $_POST["secret_a"];
$day = $_POST["day"];
$month = $_POST["month"];
$year = $_POST["year"];
$terms = $_POST["terms"];
$marketing = $_POST["marketing"];
$eighteen = $_POST["over_18"];
$date = date('d-m-Y');
$ip = $_SERVER['REMOTE_ADDR'];
$sess = session_id();
$user_exist = "SELECT * from members where username = '$username'";
$exist_record = mysql_query($user_exist);
$num = mysql_num_rows($exist_record);
if ($num > 0){
$erm = "
<script>
alert('That username has already been taken please choose another');
history.go(-1);
</script>
";
}
if ($erm == ""){
mysql_query("INSERT into members (id,username,password,forename,surname,street_address,town, region,postcode,tel,email,secret_q,secret_a,d_dob,m_dob,y_dob, agreement,marketing,eighteen,active,payment_key,signup_date,ip_signup_address, opened_shop,sess) VALUES ('','$username','$password','$forename','$surname','$street_address', '$town','$region','$postcode','$tel','$email','$secret','$answer','$day', '$month','$year','$terms','$marketing','$eighteen','0','0','$date','$ip','0', '$sess')") or die(mysql_error());
}
if ($erm == ""){
$to = '$email';
$knownsender = 'admin@example.com'; //this should be an email address that is known to the server
//server
$subject = 'LOCAL HEAT CONFIRMATION';
$message = "message <br /><a href='http://www.example.com/email_confirm.php?confirmation=$sess'>Please click this link to confirm your email address.</a>";
$headers = 'from: $knownsender\r\n';
$headers .= 'MIME-Version: 1.0\r\n';
$headers .= 'Content-type: text/html; charset=iso-8859-1' . '\r\n';
mail($to, $subject, $message, $headers);
}
?>
<html>
<head>
<? echo "$erm"?>
</head>
<body>
</body>
</html>
The thing is, it wasnt working, I changeed the html in the HEADER section for the email and it fixed it, I left it for an hour and then i broke again,
Ive been to the hosting company to see if there is a problem and get a little support and they said they dont offer support on external sripts, very friendly i thought ;)
Ok so, heres the challenge should you choose to accept it,
1. Where am I going wrong?
2. Do you know how to fix it?
3. Do you want dinner in return for fixing it?
thanx in advance people,
Diegomh7
[edited by: dreamcatcher at 10:14 am (utc) on Mar. 12, 2007]
[edit reason] Exemplified urls, fixed side scroll. [/edit]
$headers = 'from: $knownsender\r\n';
Change that to
$headers = "From: $knownsender\r\n";
Note the double quotes. Variables inside a single-quoted string will not get parsed, and \r\n will be used literally. (the same goes for the next lines).
Also, you really should look into preventing SQL injections. Always validate user input, and use mysql_real_escape_string() [php.net] on strings you insert into the database.
ive done this
if ($erm == ""){
$to = "$email";
$knownsender = "admin@example.com"; //this should be an email address that is known to the server
//server
$subject = "LOCAL HEAT CONFIRMATION";
$message = "message <br /><a href='http://www.example.com/email_confirm.php?confirmation=$sess'>Please click this link to confirm your email address.</a>";
$headers = "From: $knownsender\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
mail($to, $subject, $message, $headers);
}
Still same problem?
any more ideas im running out,
thanx in advance,
Diego
[edited by: eelixduppy at 3:57 pm (utc) on Mar. 12, 2007]
[edit reason] exemplified domain [/edit]
erm,
this is what i got now,
$to = "$email";
$subject = 'LOCAL HEAT CONFIRMATION';
$message = "message <br /><a href='http://www.example.co.uk/email_confirm.php?confirmation=$sess'>Please click this link to confirm your email address.</a>";
// 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' . "\n";
// Additional headers
$headers .= 'From: admin@example.co.uk <admin@example.co.uk>' . "\n";
//$headers .= 'Bcc: $Bcc' . "\r\n";
## Do the Email Action
mail($to, $subject, $msg, $headers) or die (mysql_error());
still same internal server error,
I also managed to piss the hosting company off,
the $to = '$email';
is the problem
the server throws an error up unless i manually type in 'me@myemail.co.uk'
erm, trying to strip slashes and allsorts with no joy,
how can i get the posted variable called $email to be sent in the $to vriable without throwing me an error up?
ideas?
its a little complicated for me to go through and figure out for this site though,
why does the $email variable not get parsed properly, why do I have to manually input a $to 'email'?
this works,
$to = 'email@email.com';
this doesnt
$to = '$email';
nor this
$to = "$email";
nor this
$to = $email;
feck!
im getting tired of it now,