Hi folks,
I'm running a small e-mail script that sends out an e-mail and adds in values such as name, e-mail address etc etc.
Its using an access database on a windows box using IIS PHP4 i think.
All e-mails are being sent in plain text but there are some issues with the e-mail address bouncing (due to domain name or user inbox not excisting) so i have had to code in reply addresses etc etc.
<?php
$batch = $_GET['batch'];
if ($batch == "")
{
echo "Please enter a batch number";
}
else
{
$conn = odbc_connect("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=accessdatabase.mdb", "", "");
if ($conn)
{
// Select query from db
$sql = "select * from table where batch = $batch";
// run query
$ecx = odbc_exec($conn, $sql);
}
else
{
// Database not connected - Likly due to it being open locally
echo "ODBC Not Connected! Please make sure you have the local database closed and try again.<BR>"; exit;
}
if ($ecx)
{
// Create First line of the table
print '<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<th scope="col">ID</th>
<th scope="col">database values</th>
<th scope="col">E-mail sent?</th>
</tr>';
$bug_workaround=0;
// Start loop from database
while(odbc_fetch_into($ecx, $inquiry))
{
// grab values from the database and put them into variables
$db_values = $inquiry[0];
// display line in table format
print '
<tr>
<td>'. $db_value .'</td>
<td>' ;
// Send Mail here
if (strtoupper(substr(PHP_OS,0,3)=='WIN')) {
$eol="\r\n";
} elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')) {
$eol="\r";
} else {
$eol="\n";
}
// Make Headers
$headers = 'From: From address<user@domain.com>'.$eol;
$headers .= 'Reply-To: From address<user@domain.com>'.$eol; // edit - removed ' as not in original code!
$headers .= 'Return-Path: From address<user@domain.com>'.$eol; // these two to set reply address
$headers .= "Message-ID: <emailid@domain.co.uk>".$eol;
$headers .= "X-Mailer: Mailer Name".$eol; // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
// Set the body text up
$body = '
e-mail body and has values in it
';
// Send the E-Mail
$sendmail = mail($email,"Subjet", $body, $headers);
// Check to see if the mail has sent
if ($sendmail)
{
print "Sent!";
}
else
{
print "Not Sent!";
exit;
}
print '</td>
</tr>';
sleep(1);
}
print '</table>'; // Close the table
}
else
{
// There was an error with the query
echo "There was an error!";
}
}
?>
I havn't got a clue why its sending blank e-mails, using a closed mail relay.
I've even sent myself 100s of e-mails and they appear to be fine!
anyone got a clue!??! 😕
Thanks in advance
Matt