...

View Full Version : php mailing script - convert from mysql to odbc for access



croix
12-30-2005, 10:01 PM
im working on a modifying a mailing list that i found, that will allow me to send email to certain addresses located in a access database.

I dont get any error, but I am not receiving the email. i setup myself in the database, residing in a state that no one else is from, so i can test mail to myself.


heres the code:



<?php

include("dbconnection.php");
if (!isset($_POST['submit'])):

?>
<html>
<head>
</head>
<body>

<?php require_once("adminOnly.php");?>

//theres more html here, but no need to paste it in

</body>
</html>


<?php else:

ini_set(SMTP, "mail.sliquid.com");
ini_set(smtp_port, 25);
ini_set(sendmail_from, "info@sliquid.com");

$to = $_POST['to'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$state = $_POST['state'];

if ("all" == $to) {
$x = 1;
$hold = 50; // quantity of emails sent before 3 sec delay
$emails ="SELECT email FROM customers";

while ($sendemail = odbc_exec($cnx,$emails)) {
$email = $sendemail["email"];
mail($email, $subject, $message, "From:Sliquid Email List <info@sliquid.com>");


$x++;
if($x == $hold) { // When $x is equal to $hold, a 3 sec delay will occur avoiding php to timeout
sleep(3);
$x = 0;
}
} // end of while loop
}

else {
$bycountry ="SELECT email FROM customers WHERE state = '$state'";
while ($statemail = odbc_exec($cnx,$bycountry)) {
$email = $statemail["email"];
$okemail = mail($email, $subject, $message, "From:Sliquid Email List <info@sliquid.com>");

$x++;
if($x == $hold) { // When $x is equal to $hold, a 3 sec delay will occur avoiding php to timeout
sleep(3);
$x = 0;
}
} // end of while loop
}

?>
<html>
<head>
</head>
<body>

SUCCESS! You will be redirected.
<?php
header("Refresh: 3; URL=http://www.sliquid.com/protected/admin.php");
echo " "; // NN4 requires that we output something...
exit();
?>

</body>
</html>
<?php endif; ?>


also, heres my dbconnection.php



<?php
$cnx = odbc_connect( 'records_db' , 'Admin', '******' );
if (!$cnx) {
Error_handler( "Error in odbc_connect" , $cnx );
}
?>

also, the ini_set stuff is from another page i have that emails properly, but i dont know if i need it for this script.

vinyl-junkie
12-31-2005, 02:25 AM
I'd put some echo statements in the code to see if the script is even executing at certain spots. For example:


$emails ="SELECT email FROM customers";
echo "emails = ". $emails . "<br><br>";

while ($sendemail = odbc_exec($cnx,$emails)) {
$email = $sendemail["email"];
echo "email = " . $email . "<br><br>";
echo "subject = " . $subject . "<br><br>";
echo "message = " . $message . "<br><br>";
mail($email, $subject, $message, "From:Sliquid Email List <info@sliquid.com>");

That should tell you where things might be going wrong.

croix
01-03-2006, 06:25 PM
thanks, I'll give it a try and report back

croix
01-04-2006, 12:00 AM
i had to change some things to make it display, but here we go.


else {
$bycountry ="SELECT email FROM customers WHERE state = '$state'";
echo "bycountry = ". $bycountry . "<br><br>";
// $bycountry = "colin@sliquid.com";
while ($statemail = odbc_exec($cnx,$bycountry)) {
$email = $statemail["email"];
echo "email = " . $email . "<br><br>";
echo "subject = " . $subject . "<br><br>";
echo "message = " . $message . "<br><br>";
$headers2 = "From: info@sliquid.com\r\n";
$headers2 .= "BCC: sales@sliquid.com\r\n";
// $okemail = mail($email, $subject, $message, $headers2);

$x++;
if($x == $hold) { // When $x is equal to $hold, a 3 sec delay will occur avoiding php to timeout
sleep(3);
$x = 0;
}
} // end of while loop
}

?>
<html>
<head>
</head>
<body>
SUCCESS! You will be redirected.
<?php
header("Refresh: 3; URL=http://www.sliquid.com/protected/admin.php");
echo " "; // NN4 requires that we output something...
exit();
?>
</body>
</html>
<?php endif; ?>

when i submit, i get this
bycountry = SELECT email FROM customers WHERE state = 'Vermont'

email =

subject = Subject - Test

message = testing 123 this is a test testing 123


then this repeats over and over, 50 times

email =

subject = Subject - Test

message = testing 123 this is a test testing 123

email =

subject = Subject - Test

message = testing 123 this is a test testing 123

etc....


so its seeing my SQL request as text.
what is wrong with the syntax?

croix
01-04-2006, 04:05 PM
anyone?

croix
01-05-2006, 04:15 PM
i think separating the sql from teh mail will help. how should i do this, without moving my query to my include page?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum