Jump to content

Recommended Posts

Hi there,

 

I am trying to use some php code to get a users email address from mysql database, can someone please check my code and see where i am going wrong?

 

<?php

$con = mysql_connect("*","*","*");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("ogs_mailinglist1", $con);

$result = mysql_query("SELECT * FROM mailinglist");

while($row = mysql_fetch_array($result))

{
  echo $row['email'] . " " ;
  echo "<br />";
  }

// Grab our config settings
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');

// Grab the FreakMailer class
require_once($_SERVER['DOCUMENT_ROOT'].'/include/MailClass.inc');

// instantiate the class
$mailer = new FreakMailer();

// Set the subject
$mailer->Subject = 'This is a test';

// Body
$mailer->Body = 'This is a test of my mail system!';

// Get the user's Email
$sql = mysql_query("SELECT email FROM users WHERE 1");

while($row = mysql_fetch_object($result))



mysql_close($con);

if(!$mailer->Send())
{
    echo 'There was a problem sending this mail!';
}
else
{
    echo 'Mail sent!';
}
$mailer->ClearAddresses();
$mailer->ClearAttachments();
?>

 

 

I think the problem is with this part:

 

// Get the user's Email

$sql = mysql_query("SELECT email FROM users WHERE 1");

 

while($row = mysql_fetch_object($result))

 

 

but i don't know how to correct it  :(

 

 

Thanks,

 

Hash

You can remove the WHERE clause, it does nothing.

 

Also, how do you know your not getting any result? You don't actually do anything with it.

 

Oh ok, i don't know if i am getting a result  :shrug:

 

i thought that this part would send the email

 

if(!$mailer->Send())

 

 

but i am not getting an email so assumed that it was a problem with getting the email from the database...

 

 

 

p.s sorry about posting database info, will be more careful in future

NLT:  yep i am using this on a server with SMTP

 

Thorpe:  Ah ok, this is the code from my MailClass file i am using if it's any help? 

 

<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/include/phpmailer.class.php');

class FreakMailer extends PHPMailer
{
    var $priority = 3;
    var $to_name;
    var $to_email;
    var $From = null;
    var $FromName = null;
    var $Sender = null;

    function FreakMailer()
    {
        global $site;

        // Comes from config.php $site array

        if($site['smtp_mode'] == 'enabled')
        {
            $this->Host = $site['smtp_host'];
            $this->Port = $site['smtp_port'];
            if($site['smtp_username'] != '')
            {
                $this->SMTPAuth = true;
                $this->Username = $site['smtp_username'];
                $this->Password = $site['smtp_password'];
            }
            $this->Mailer = "smtp";
        }
        if(!$this->From)
        {
            $this->From = $site['from_email'];
        }
        if(!$this->FromName)
        {
            $this-> FromName = $site['from_name'];
        }
        if(!$this->Sender)
        {
            $this->Sender = $site['from_email'];
        }
        $this->Priority = $this->priority;
    }
}
?>

 

 

 

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.