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.

    I don't know if this helps much but I had a similar problem with sending emails via sendmail and had to ask my web host provider about it. They replied that instead of using "From:", I had to use the "-f" switch instead. For example...

    	if(!(mail($email1, $subject, $message, $headers, "-f noreply@mysite.com"))) {		
    		$error_msg = "Failed to send account activation email. Please see admin.";
    		return false;
    	}
    

      thanks, i'll give this a try, but the mail function works on other pages i have, so i dont think this is the issue.

        no, same issue. From works fine on my server, the problem lies in the PHP.

        check this out.

        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?

          anyone help with getting this thing to actaully pull data, and not loop on pointlessly?

            i think i need to separate the sql query from the mail function.

            whats the best way to do this? I know i could put it on my include page, but thats prolly not the best.

              Write a Reply...