Page 3 of 4

Re: Issue with mailing list

Posted: Mon May 30, 2011 11:07 pm
by pasqo83
Hi Jacek,

I've only just started to test the scripts properly now (as I did the test as I went along and it all seemed fine but now but now the remove function does not work again. I rewrote the code from the tutorial but is not working. It looks as though everything is working as it should though. Is there any suggestions or Ideas?
<?php

// ADDS DETAILS INTO THE DB
function add_user($email){
	$email = mysql_real_escape_string($email);
	$result = mysql_query ("INSERT INTO `users` (`email`) VALUES (`{$email}`)"); 
	
	return ($result !== false) ? true : false;	
}

// REMOVES THE EMAIL ADDRESS FROM THE TABLE
function remove_user($email){
        $email = mysql_real_escape_string($email);
       
        mysql_query("DELETE FROM `users` WHERE `email` = `{$email}`");
               
}

// SENDS MESSAGE TO ALL USRES

$headers = array (
	'From: name@website.co.uk'. "\r\n" .
	'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
    'X-Mailer: PHP/' . phpversion() 

);


function mail_all($subject, $message, $headers){
	$users = mysql_query("SELECT `email` FROM `users`");
	
	while (($user = mysql_fetch_assoc($users))!== false){
	$body = "Hi, <p></p> {$message} <p></p>
	
	<b>Unsubscribe:</b> http://www.nameofsite/content/subscribe ... ail={$user['email']}";
	
	mail($user['email'], $subject, $body, $headers);
	
	}
	
}
Many Thanks :)

Re: Issue with mailing list

Posted: Mon May 30, 2011 11:20 pm
by Temor
try changing this line:
mysql_query("DELETE FROM `users` WHERE `email` = `{$email}`");
to
mysql_query("DELETE FROM `users` WHERE `email` = '{$email}'");
( i.e change `{$email}` (backticks) to '{$email}' (semicolons) )

///
You could also remove the bacticks from this:
 WHERE `email` 

Re: Issue with mailing list

Posted: Mon May 30, 2011 11:48 pm
by pasqo83
Temor wrote:try changing this line:
mysql_query("DELETE FROM `users` WHERE `email` = `{$email}`");
to
mysql_query("DELETE FROM `users` WHERE `email` = '{$email}'");
( i.e change `{$email}` (backticks) to '{$email}' (semicolons) )

///
You could also remove the bacticks from this:
 WHERE `email` 

Hi Thanks, I tried this but it didn't remove the email address :(
Im really confuzzled (confused) to what it is :(

Re: Issue with mailing list

Posted: Tue May 31, 2011 11:02 am
by jacek
pasqo83 wrote:Hi Thanks, I tried this but it didn't remove the email address :(
Im really confuzzled (confused) to what it is :(
Try adding
echo mysql_error();
after the failing query and see if mysql tells you what the problem is.

Re: Issue with mailing list

Posted: Tue May 31, 2011 11:34 am
by pasqo83
Thanks, i'll try it tonight when I get home.

Im starting to understand php alot better now though considering what I used to know. :)

Re: Issue with mailing list

Posted: Tue May 31, 2011 11:12 pm
by pasqo83
This is turning into a disaster, I may end up redoing the whole mailing list again.

I have just tried putting in the error mysql_error(); but nothing comes up.

I have now gone back to my main page and every email address I enter keeps saying "There is something wrong, you may have already entered this email address before" -

How do I check the $errors string as im sure it was working before :(
if (isset($_POST['email'])){
	$errors= array();
	
	if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false){
	$errors[] = 'The email address you gave does not appear to be valid.';
	}

	if (empty($errors)){
		if (add_user($_POST['email']) === false){
		$errors[] = 'Something went wrong, you may have already subscribed';
		
		echo $errors;
	}

}
?>
<?php

if (empty($errors) === false){
	echo implode($errors);
		
} else if (isset($errors) === false){
	echo 'Fill in the form to subscribe';
} else{ 
	echo 'You have been subscribed, thanks';
	}
}
?>

Re: Issue with mailing list

Posted: Wed Jun 01, 2011 12:12 am
by pasqo83
Ok, im not sure how but I managed to remove to sort out the issue with removing the email. Now the issue i am facing is adding a user into the subscription place.

here are the codes if anyone can help please.

information from my index.php
if (isset($_POST['email'])){
	$errors= array();
	
	if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false){
	$errors[] = 'The email address you gave does not appear to be valid.';
	}

	if (empty($errors)){
		if (add_user($_POST['email']) === false){
		$errors[] = 'Something went wrong, you may have already subscribed';
		
	}

}
?>
<?php

information from my mail.inc.php (just the add users)
// ADDS DETAILS INTO THE DB
function add_user($email){
	$email = mysql_real_escape_string($email);
	$result = mysql_query ("INSERT INTO `users` ('email') VALUES (`{$email}`)"); 
	
	return ($result !== false) ? true : false;	
}

// REMOVES THE EMAIL ADDRESS FROM THE TABLE
function remove_user($email){
        $email = mysql_real_escape_string($email);
       
	    mysql_query("DELETE FROM `users` WHERE 'email' = '{$email}'");
               
}

Re: Issue with mailing list

Posted: Wed Jun 01, 2011 7:53 am
by Temor
I'm going for pretty much the same approach this time.

Try changing
('email') VALUES (`{$email}`)
to
(`email`) VALUES ('{$email}')

Re: Issue with mailing list

Posted: Wed Jun 01, 2011 8:20 am
by pasqo83
Temor wrote:I'm going for pretty much the same approach this time.

Try changing
('email') VALUES (`{$email}`)
to
(`email`) VALUES ('{$email}')
A really big thank you to you Temor. It now finally works :D

What is the difference betweene between the `` and the ' '
I can't believe a simple backtick or quote can make such a big impact.

Thank you again Temor :D :D

Re: Issue with mailing list

Posted: Wed Jun 01, 2011 8:26 am
by jacek
pasqo83 wrote:What is the difference betweene between the `` and the ' '
I can't believe a simple backtick or quote can make such a big impact.
Backticks indicate that the thing inside them should be treated as a table or column name. Quotes mean it should be treated as a string.

Re: Issue with mailing list

Posted: Wed Jun 01, 2011 1:10 pm
by pasqo83
jacek wrote: Backticks indicate that the thing inside them should be treated as a table or column name. Quotes mean it should be treated as a string.
Ah I see, it makes sense now. Now when I look at that coding I can understand what is a table/column name and what is a string.

One last question. Now that I've created this into a HTML format, how do I press enter to create a a new line with using the <br/> or <p> functions? Is there anyway to sort that out as well?

Just wanted to say as well, thanks for the help Jacek, temor and the rest of the people who gave me advise. Really is appreciated. I rarely come onto forums but this is actually my home of forums for me. Thanks :)

Re: Issue with mailing list

Posted: Wed Jun 01, 2011 2:00 pm
by Temor
pasqo83 wrote:Thank you again Temor :D :D
You're welcome!

Hopefully, you'll help me when I'm stuck as well :D

Re: Issue with mailing list

Posted: Wed Jun 01, 2011 3:53 pm
by pasqo83
Temor wrote:
pasqo83 wrote:Thank you again Temor :D :D
You're welcome!

Hopefully, you'll help me when I'm stuck as well :D
Defo, once I complete this website for my friend, I am going to dedicate some time on php so I can understand the basics and MySql and how it operates so hopefully I can help with your querys as well one day. :D

Oh and do you know how to create spaces between each sentence without having to put a <br /> or a <p></p> into the mailing list. I created a HTML mailing list and need my friend to use it without using the codes (as he is very very very simple). :oops:

If not, I will try and dig it into him to use that,

Re: Issue with mailing list

Posted: Wed Jun 01, 2011 4:18 pm
by jacek
nl2br() will replace linebreaks with <br / > tags, is that what you are trying to do ?

Re: Issue with mailing list

Posted: Wed Jun 01, 2011 5:22 pm
by pasqo83
jacek wrote:nl2br() will replace linebreaks with <br / > tags, is that what you are trying to do ?
Basically I have assigned the mailing list to send mail as a html. Now the send_mail.php (from the mailing list tutorial), I want when I write in message box and I press the enter key it already does it does a line break or paragraph already. It is because i am doing a website for someone who has not HTML knowledge at all so all they would need to do is type away without having to do any coding.

Does that make sense? :oops:

Re: Issue with mailing list

Posted: Wed Jun 01, 2011 5:24 pm
by Temor
pasqo83 wrote:
jacek wrote:nl2br() will replace linebreaks with <br / > tags, is that what you are trying to do ?
Basically I have assigned the mailing list to send mail as a html. Now the send_mail.php (from the mailing list tutorial), I want when I write in message box and I press the enter key it already does it does a line break or paragraph already. It is because i am doing a website for someone who has not HTML knowledge at all so all they would need to do is type away without having to do any coding.

Does that make sense? :oops:
Yes, it does, and I do believe that nl2br() does just that.
http://se2.php.net/manual/en/function.nl2br.php

Re: Issue with mailing list

Posted: Wed Jun 01, 2011 6:11 pm
by pasqo83
Thanks,

I just realised something really strange. I have used my hotmail.co.uk and hotmail.com and gmail account to test the mails going through and it works. But I have just got my friend to do it and my brother (between them 6 email address's) and its not pulling through on their emails.

Any ideas?

My coding from the send_mail.php
<?php

include('../../core/init.inc.php');

$headers = array (
	'Reply-To: Spaghetti John Offers <Gianni@spaghettijohns.co.uk>'. "\r\n" .
	'Return-Path: Offers at Spaghetti John <Gianni@spaghettijohns.co.uk>'. "\r\n" .
	'From: Offers at Spaghetti John <Gianni@spaghettijohns.co.uk>'. "\r\n" .
	'Organization: Spaghetti Johns'."\r\n" .
	'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
    'X-Mailer: PHP/' . phpversion() 

);


if (isset($_POST['subject'], $_POST['message'])){
	mail_all($_POST['subject'], $_POST['message'],
implode ($headers));
}

?>

Re: Issue with mailing list

Posted: Wed Jun 01, 2011 6:35 pm
by jacek
It may have been delivered to the Junk folder, did you ask them to check there ?

Re: Issue with mailing list

Posted: Wed Jun 01, 2011 6:42 pm
by pasqo83
Yeah they checked both sections but nothing, I even checked 2 of my brothers emails and there was nothing there. I dont understand that. Was the last codes I sent ok? I pretty much copied that from the headers website you sent me.

Re: Issue with mailing list

Posted: Wed Jun 01, 2011 6:47 pm
by pasqo83
Ive just noticed hotmail.com and live.co.uk is not working. Hotmail.co.uk and gmail.com seems to work. :?

Re: Issue with mailing list

Posted: Wed Jun 01, 2011 7:08 pm
by jacek
Could you try just sending to that one email address not as a list of many, it could be some kind of flood control ? I'm guessing now really ;)