Jump to content

Recommended Posts

I am tring to use the code below to loop thru my table and send mail to all addresses where subscription is about to expire. I get no errors but mail does not send.

 

<?php

$ds = date("Y-m-d",strtotime("+8 days"));

include("sharons_dbinfo.inc.php");

mysql_connect(mysql,$username,$password);

@mysql_select_db($database) or die( "Unable to select database");

 

$query = "select field3 from test WHERE field4 = '$ds'";

$result=mysql_query($query) or die (mysql_error());

if (($result)||(mysql_errno == 0))

{

 

  if (mysql_num_rows($result)>0)

  {

 

          $i = 0;

          while ($i < mysql_num_fields($result))

          {

 

      $i++;

}

    //display the data

    while ($rows = mysql_fetch_array($result,MYSQL_ASSOC))

    {

      echo "<br>";

      foreach ($rows as $data)

      {

$to = "$data";

$subject = "Your Subscription";

$message="Your subscription will expire in seven days."

$headers = "From: webmaster@somewhere.com";

$sent = mail($to, $subject, $message, $headers) ;

if($sent)

{print "Your mail was sent successfully"; }

else

{print "We encountered an error sending your mail"; }

      }

    }

  }else{

    echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>";

  }

  echo "</table>";

}else{

  echo "Error in running query :". mysql_error();

}

?>

Link to comment
https://forums.phpfreaks.com/topic/87789-solved-help-with-sending-mail/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.