I'm having a little trouble with one of my queries.
Basically I have a 'register' page which enters a user's information, making it valid for one month. The INSERT is working fine, but I'd appreciate any pointers on how to combine a mail() function with it, which emails a predefined message along with their username and password and the membership number which is automatically assigned by the server. The mail isn't currently sending (or at least I'm not receiving it - I used this mail script (I think it was this one) successfully a while back, but only received a handful of the messages, and the rest (about 15) came through over the next 4 days even though they were sent all in the same 2 hour period.
You can see my current code below, messy as it is! (Any cleanup tips also gratefully received!)
require_once('../sypphp/sypcms/DbConnector3.php');
$errorlist = array();
$title=$_POST['title'];
$firstname=$_POST['firstname'];
$surname=$_POST['surname'];
$dobday=$_POST['dobday'];
$dobmonth=$_POST['dobmonth'];
$dobyear=$_POST['dobyear'];
$memstatus=$_POST['memstatus'];
$memtype=$_POST['memtype'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$city=$_POST['city'];
$county=$_POST['county'];
$postcode=$_POST['postcode'];
$country=$_POST['country'];
$email=$_POST['email'];
$password=$_POST['password'];
$oxevents=$_POST['oxevents'];
$scotevents=$_POST['scotevents'];
$allevents=$_POST['allevents'];
$jobsbulletin=$_POST['jobsbulletin'];
$mobtel=trim($_POST['mobtel']);
$daytel=trim($_POST['daytel']);
$evetel=trim($_POST['evetel']);
$company=$_POST['company'];
$position=$_POST['position'];
$department=$_POST['department'];
$companyrep=$_POST['companyrep'];
$college=$_POST['college'];
$course=$_POST['course'];
$collegerep=$_POST['collegerep'];
//validate the fields
if (trim($_POST['firstname']) == '') {$errorlist[] = 'You have not entered a First Name';}
if (trim($_POST['surname']) == '') {$errorlist[] = 'You have not entered a Surname';}
if (trim($_POST['address1']) == '') {$errorlist[] = 'You have not entered an Address/Streetname/number';}
if (trim($_POST['postcode']) == '') {$errorlist[] = 'You have not entered a Postcode';}
if (trim($_POST['email']) == '') {$errorlist[] = 'You have not entered an email address';}
if (trim($_POST['password']) == '') {$errorlist[] = 'You have not entered a password';}
if (!checkdate($_POST['dobmonth'], $_POST['dobday'], $_POST['dobyear'])){$errorlist[] = 'Please enter a valid Date of Birth';}
//if (!checkdate($_POST['joinmonth'], $_POST['joinday'], $_POST['joinyear'])){$errorlist[] = 'Please enter a valid Join Date';}
//if (!checkdate($_POST['expmonth'], $_POST['expday'], $_POST['expyear'])){$errorlist[] = 'Please enter a valid Expiry Date';}
if (sizeof ($errorlist) == 0)
{
$connector = new DbConnector();
$dobtimestamp = array($dobyear, $dobmonth, $dobday);
$postdob = implode("-", $dobtimestamp);
/*
$jointimestamp = array($joinyear, $joinmonth, $joinday);
$postjoin = implode("-", $jointimestamp);
$exptimestamp = array($expyear, $expmonth, $expday);
$postexp = implode("-", $exptimestamp);*/
$insertQuery = "INSERT INTO mem_details (title, firstname, surname, dob, memstatus, memtype, joindate, expdate, address1, address2, city, county, postcode, country, email, oxevents, scotevents, allevents, jobsbulletin, mobtel, daytel, evetel, company, position, department, companyrep, college, course, collegerep, notes, dateadded, moddate, mem_paid, password
) VALUES ('$title', '$firstname', '$surname', '$postdob', '$memstatus', '$memtype', NOW(), DATE_ADD(NOW(), INTERVAL 1 MONTH), '$address1', '$address2', '$city', '$county', '$postcode', '$country', '$email', '$oxevents', '$scotevents', '$allevents', '$jobsbulletin', '$mobtel', '$daytel', '$evetel', '$company', '$position', '$department', '$companyrep', '$college', '$course', '$collegerep', '$notes', NOW(), NOW(),'', '$password')";
$result = $connector->query($insertQuery) or exit('Error in query: ' . $insertQuery . ' ' . mysql_error());
//DATA SUBMITTED, TELL US and TELL THE USER
$sendmail = $connector->query('SELECT * FROM mem_details WHERE email = "$email"')or die ("Error in Query: $query.".mysql_error());
if (mysql_num_rows($sendmail) > 0)
{
while ($row = mysql_fetch_array($sendmail))
{
//START MAIL
$text = '<img src="http://www.thesyp.org.uk/images/mailheader.gif">';
$text .= '<font face="verdana" size="2"><p>Dear '. $row['firstname'].'</p></font>';
$text .= '<p>Thank you for signing up to the SYP, we hope you benefit as much as many of our other members.</p>
Below you will find the details as you submitted them:
Your email/username: '.$row['email'].'<br>
Your password: '.$row['password'].'<br>
Your membership number: '.$row['memnum'].'<br>'.'';
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: SYP website <info@thesyp.org.uk>\n";
$mailto = $row['email'];
$mailto .= "webmaster@thesyp.org.uk";
mail($mailto, "Your SYP Details", $text, $headers);
}//end while
}//end if rows returned