Page 1 of 1

mail() function what kind of error is that!?!

Posted: Mon Mar 15, 2004 5:09 am
by phpnovice
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.

Code: Select all

<?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?

Cheers guys for any help offered!

James

8)

Posted: Mon Mar 15, 2004 5:21 am
by twigletmac
What is the full error message?

Mac

Posted: Mon Mar 15, 2004 6:19 am
by phpnovice
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?

Posted: Mon Mar 15, 2004 6:34 am
by twigletmac
Could it be a MySQL error - what does the showerror() function do?

Mac

Posted: Mon Mar 15, 2004 6:37 am
by phpnovice
just this havent got round to making it more robust yet. i.e. cant be arsed

Code: Select all

<?php

function showerror()
{
	die("Error " . mysql_errno() . " : " . mysql_error());
}

?>
i am checking mysql errors but they seem to be working ok if i print them out. just get that and the lovely Error 0!

Posted: Mon Mar 15, 2004 6:42 am
by twigletmac
To check if it is the mail function playing silly buggers change the mail() call to include an or die() statement:

Code: Select all

mail($to, $subject, $out, $headers) or die('The mail() function has failed!');
Mac

Posted: Mon Mar 15, 2004 6:52 am
by phpnovice
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!

Posted: Mon Mar 15, 2004 7:19 am
by phpnovice
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