PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hey im trying to send a simple email generated when someone sends an order. everything is validated and stored in the session where needed but i just keep getting a response "Error 0:" and no email sent to me. this is the script i have so far.
<?php
//include details for logging onto mysql database
include 'mysql.php';
//include error function
include 'error.php';
error_reporting(E_ALL);
// Send the user an email
function send_confirmation_email($custID, $orderID, $connection)
{
// Find customer information
$query1 = "SELECT DISTINCT * FROM customer WHERE custid = " . $_SESSION["userid"];
//Run the query through the connection to mysql with some error handling
if(!($query1 = @ mysql_query($query1,$connection)))
showerror();
// There is only one matching row
$row = @ mysql_fetch_array($query1);
//setting up the "to" address
$to = $row["cust_name"] . " <" . $row["email"] . ">";
// setup the "subject" line
$subject = "Jims Bargain Basement DVD's Order Confirmation";
// And, last (before we build the email), set up some mail headers
$headers = "From: Jims Bargain Basement DVDs <some@email.co.uk>\r\n";
$headers .= "X-Sender: <some@email.co.uk>\r\n";
$headers .= "X-Mailer: PHP\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "Return-Path: <some@email.co.uk>\r\n";
// Now, put together the body of the email
//Body here
$out="Congrats";
// Send the email!
mail($to, $subject, $out, $headers);
}
// Main ----------
// Re-establish the existing session
session_start();
$custID = $_SESSION["userid"];
$orderid= $_SESSION["sessionorderid"];
//connect to mysql with some error handling
if (!($connection = @ mysql_pconnect($host, $user, $passwd)))
die("Could not connect to the database");
showerror();
//select my database with some error handling
if(!mysql_select_db($dbName, $connection))
showerror();
// Send the user a confirmation email
send_confirmation_email($custID, $orderID, $connection);
//close the connection to mysql with some error handling
if(! mysql_close($connection))
showerror();
// Redirect to a receipt page (this can't be the receipt page,
// since the reload problem would cause extra emails).
header("Location: /completeorder.php");
?>
Can anyone help me out? im not really sure whats wrong with it? could it be the server that im running off? i.e. should i contact the uni systems admin and tell them to sort it? or am i missing something?
thats it just Error: 0 no quotes nothing else and i have all error reporting on. im wondering is it anything to do with the header does the from and x-sender address have to be a real address or can it just be a generic one?
ok now i have added do or dies to all my sql related actions and i still get nothing but error 0:. a also added in a print query1; after making the query1 string but that doesnt get printed either. so it must be dying somewhere before there. but i cant see where.
this is the most annoying error yet!
Ah wonder of all wonders! i got it working. just recieved a nice congratulation email from myself! haha. i dont know how, i just re-arranged it a bit and after some fiddling suddenly worked.
Cheers for your help!
James