Page 1 of 1

mailing list problem

Posted: Wed Sep 06, 2006 4:27 am
by rsmarsha
I have a mailing list setup, where admin enters some text into a textarea to set the text thats sent in the list.

The list is sent with :

Code: Select all

$mesg = $mr['list_text'];
Where $mr is the row pulled from the database containing the text.

If the query to pull out the info is :

Code: Select all

$mail = "SELECT mailing_users.email,mailing_lists.list_text FROM mailing_users,mailing_lists WHERE mailing_users.list_id=mailing_lists.list_id AND mailing_users.list_id=".$list."";
$mr = mysql_fetch_assoc($mq);
I thought putting '.$mr['email'].' in the textarea would pull from the row and insert that variable into the messge. It doesn't work. :( Any ideas on the best way to get this working?

Posted: Wed Sep 06, 2006 4:54 am
by andym01480

Code: Select all

$mail = "SELECT mailing_users.email AS email,mailing_lists.list_text AS list_text FROM mailing_users,mailing_lists WHERE mailing_users.list_id=mailing_lists.list_id AND mailing_users.list_id='$list'";
$mq=mysql_query($mail) or die ("Couldn't access query"); // need to do the query!
$mr = mysql_fetch_assoc($mq);
Need to do the query!
Also added to AS to name what you are grabbing.

See if that works!

Posted: Wed Sep 06, 2006 5:04 am
by rsmarsha
Oops, just forgot to post that query bit, hehe.

Anyway, tried the AS and still get the same. Does it matter that when the mail is sent it's sent using a class?

Code: Select all

$mail->send_list();
The query i posted is inside that function

Code: Select all

function send_list()
{
	$list = $this->list_id;
	$mail = "SELECT mailing_users.email AS email,mailing_lists.list_text FROM mailing_users,mailing_lists WHERE mailing_users.list_id=mailing_lists.list_id AND mailing_users.list_id=".$list."";
	$mq = mysql_query($mail) or die("Query $mail Failed".mysql_error());
	while ($mr = mysql_fetch_assoc($mq))
	{
	//mail
	$emailto = $mr['email'];
	$additional_headers = 'From: emailhere';
 	$subj = 'Mailing List';
	$mesg = $mr['list_text'];
	mail($emailto, $subj, $mesg, $additional_headers) or die('sms mail not sent');
	}
}

Posted: Wed Sep 06, 2006 5:20 am
by andym01480
No idea about the class. I'd add some echo's to see that the query is doing what you want it to before trying to get mail() working! Oh and the header needs an \r\n

Code: Select all

function send_list()
{
        $list = $this->list_id;
        $mail = "SELECT mailing_users.email AS email,mailing_lists.list_text FROM mailing_users,mailing_lists WHERE mailing_users.list_id=mailing_lists.list_id AND mailing_users.list_id=".$list."";
        $mq = mysql_query($mail) or die("Query $mail Failed".mysql_error());
        while ($mr = mysql_fetch_assoc($mq))
        {
        //mail
        $emailto = $mr['email'];
echo "$emailto<br>";
        $additional_headers = 'From: emailhere\r\n';//needs the \r\n to work!
        $subj = 'Mailing List';
        $mesg = $mr['list_text'];
echo "$mesg";
        //mail($emailto, $subj, $mesg, $additional_headers) or die('sms mail not sent');
        }
}

Posted: Wed Sep 06, 2006 5:27 am
by rsmarsha
The query works fine, and the mail sends without the /r/n.

I just need to figure out how to put varaibles into the textbox so when they are later drawn out they will send in the mail.

At the moment the mail sent looks like this.

Code: Select all

This is a 
test mailing list 

 '.$mr['email'].'
It should be

Code: Select all

This is a 
test mailing list 

emailaddress

Posted: Wed Sep 06, 2006 5:37 am
by andym01480
Confused!

So are you saying the problem is not with the code thus posted, but with a form the admin is using? In other words the form has posted $mr['email'] as is rather than contents of that variable to the database?

Posted: Wed Sep 06, 2006 5:42 am
by rsmarsha
Yeah i post some text into the db which is then mailed with $mesg = $mr['list_text'];.

I want the mail text to be able to contain variables of the users choosing from the query i posted above.