Chris1989
11-03-2010, 11:15 AM
Its probably just a simple noob error, (i am new to PHP) but the following code will execute fine but only send the email...
<?php
if (isset($_REQUEST['email']) && $_REQUEST['email'] != '') {
$to = "my@email.com";
$subject = "Contact Details Captured";
$message = "New message from: {$_REQUEST['fname']} {$_REQUEST['sname']} {$_REQUEST['email']}.\r\n\r\n {$_REQUEST['telno']}";
$message .= $_REQUEST['message'];
mail($to,$subject,$message);
$dbserver = "localhost";
$dbuser = "myusername";
$dbpwd = "mypassword";
$dbcon = mysql_connect("$dbserver", "$dbuser", "$dbpwd");
mysql_select_db("test", $dbcon);
$query = "INSERT INTO captured_data (fname, sname, email, telno) VALUES ('$_POST[fname]','$_POST[sname]','$_POST[email]','$_POST[telno]')";
mysql_query($query, $dbcon);
mysql_close($dbcon);
header('Location:http://www.myurl.co.uk/home');}
else{
header('Location:http://www.myurl.co.uk/error.php#forma');
exit();
}
?>
and doing it the following way will add the data to my database but not send the email.
<?php
if (isset($_REQUEST['email']) && $_REQUEST['email'] != '') {
$to = "my@email";
$subject = "Contact Details Captured";
$message = "New message from: {$_REQUEST['fname']} {$_REQUEST['sname']} {$_REQUEST['email']}.\r\n\r\n {$_REQUEST['telno']}";
$message .= $_REQUEST['message'];
$dbserver = "localhost";
$dbuser = "myusername";
$dbpwd = "mypassword";
$dbcon = mysql_connect("$dbserver", "$dbuser", "$dbpwd");
mysql_select_db("test", $dbcon);
$query = "INSERT INTO captured_data (fname, sname, email, telno) VALUES ('$_POST[fname]','$_POST[sname]','$_POST[email]','$_POST[telno]')";
mysql_query($query, $dbcon);
mysql_close($dbcon);
mail($to,$subject,$message);
header('Location:http://www.myurl.co.uk/home');}
else{
header('Location:http://www.myurl.co.uk/error.php#forma');
exit();
}
?>
As I said it is probably a basic misunderstanding of the PHP the syntax.
Cheers, Chris.
<?php
if (isset($_REQUEST['email']) && $_REQUEST['email'] != '') {
$to = "my@email.com";
$subject = "Contact Details Captured";
$message = "New message from: {$_REQUEST['fname']} {$_REQUEST['sname']} {$_REQUEST['email']}.\r\n\r\n {$_REQUEST['telno']}";
$message .= $_REQUEST['message'];
mail($to,$subject,$message);
$dbserver = "localhost";
$dbuser = "myusername";
$dbpwd = "mypassword";
$dbcon = mysql_connect("$dbserver", "$dbuser", "$dbpwd");
mysql_select_db("test", $dbcon);
$query = "INSERT INTO captured_data (fname, sname, email, telno) VALUES ('$_POST[fname]','$_POST[sname]','$_POST[email]','$_POST[telno]')";
mysql_query($query, $dbcon);
mysql_close($dbcon);
header('Location:http://www.myurl.co.uk/home');}
else{
header('Location:http://www.myurl.co.uk/error.php#forma');
exit();
}
?>
and doing it the following way will add the data to my database but not send the email.
<?php
if (isset($_REQUEST['email']) && $_REQUEST['email'] != '') {
$to = "my@email";
$subject = "Contact Details Captured";
$message = "New message from: {$_REQUEST['fname']} {$_REQUEST['sname']} {$_REQUEST['email']}.\r\n\r\n {$_REQUEST['telno']}";
$message .= $_REQUEST['message'];
$dbserver = "localhost";
$dbuser = "myusername";
$dbpwd = "mypassword";
$dbcon = mysql_connect("$dbserver", "$dbuser", "$dbpwd");
mysql_select_db("test", $dbcon);
$query = "INSERT INTO captured_data (fname, sname, email, telno) VALUES ('$_POST[fname]','$_POST[sname]','$_POST[email]','$_POST[telno]')";
mysql_query($query, $dbcon);
mysql_close($dbcon);
mail($to,$subject,$message);
header('Location:http://www.myurl.co.uk/home');}
else{
header('Location:http://www.myurl.co.uk/error.php#forma');
exit();
}
?>
As I said it is probably a basic misunderstanding of the PHP the syntax.
Cheers, Chris.