send Mail
Posted: Thu Jan 08, 2009 2:30 pm
Hi there,
I have a form that updates a database (inputs a new row with the form inputs).
I also want an email to be sent out when the form is submitted. I understand that the form can only have 1 action so I have done the following.
When the form is submitted, it runs the following function to update the database:
As you can see, the above code then runs the sendMail function below:
The problem is, I am getting 'There was an issue sending your results. Sorry' when I submit the form.
The database is getting updated which is great but I need the email to be sent.
The above code is part of a php class, can i have a $mailSent script within a class? or is there something else wring with my code?
Can anyone help?
Thanks
I have a form that updates a database (inputs a new row with the form inputs).
I also want an email to be sent out when the form is submitted. I understand that the form can only have 1 action so I have done the following.
When the form is submitted, it runs the following function to update the database:
Code: Select all
public function productInsert(){
if(isset($_GET['insert'])){
include('classes/Security.class.php');
$security = new Security();
$security->escapeInput();
//catch the vars
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$idnum = $_POST['idnum'];
$mincont = $_POST['mincont'];
$govcont = $_POST['govcont'];
//insert new data into db
$query = "INSERT INTO products (name, email, number, idnum, mincont, govcont, code, price) VALUES ('$name', '$email', '$number', '$idnum', '$mincont', '$govcont', '$code', '$price')";
$result = mysql_query($query);
if (!$result) {
echo "Could not insert values into the database. ". mysql_error();
} else {
$this->sendMail();
}
}
}//productInsertCode: Select all
public function sendMail(){
$recipient = "peterjunsworth@gmail.com";
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$idnum = $_POST['idnum'];
$subject = "Assessment results";
$body = "
You have recieved Kiwisaver Assessment Results. \n\n
Personal Details: \n
Name: \t $name \n
Email:\t $email \n
Phone:\t $number \n
";
$headers = "From: $email \n";
$mailSent = mail($recipient, $subject, $body, $headers);
if (!$mailSent) {
header("Location:index.php?id=".$productID."&status= There was an issue sending your results. Sorry");
} else {
header("Location:index.php?status=Your assessment has been submitted to Huljich Wealth Management");
}
}The database is getting updated which is great but I need the email to be sent.
The above code is part of a php class, can i have a $mailSent script within a class? or is there something else wring with my code?
Can anyone help?
Thanks