You are currently viewing the BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
If someone subscribes via email, then changes the name associated with their email address, that the script fails to recognise their email and thus treats posts to the mailing list as coming from an unsubscribed email address??
Sign-up email address as stored in mysql database:
"Joe Bloggs" <firstname.lastname@example.org>
Then Joe changes his name in, say, Outlook too:
What I'm finding is that even though it's the same email address, the "Joe Bloggs" <email@example.com> is what stored in the database so if Joe changes drops his surname, when the database query is run from the script, it doesn't match...
Unless it's simply a problem that I have, it's quite an issue with the script as there is no way to ensure that people don't change there names!
The other issue I've notice is that if a subscription is made via Hotmail,
then the address is stored as follows in the database:
Claire MacPherson <firstname.lastname@example.org>
So, that's a second format and possibly another problem?!
In the manage.php file, all the database transactions
match on the exact entry, so I would expect the results
you are getting.
The SQL statements in this file always uses the
relational operator "Equal to" (=)
WHERE EMAIL_ADDR = "%s"
So it will match only on exactly what is in the database.
(The %s is always the $from variable in this file)
You would need to enhance the code to deal with the
situation you have. That could be a lot of work, and
I am not sure you would want to do it anyway.
You could do something like parse the $from variable.
Perhaps extract out the email portion, and the display
name into variables.
You could combine that with using the LIKE operator
in your SQL statements, this would allow you to use
wildcards on your searches.
For example, in your case, the statement
WHERE EMAIL_ADDR LIKE '"%" <email@example.com>'
would match on
"Joe Bloggs" <firstname.lastname@example.org>
or any other name inside the quotes.
Having said this, I am not sure you would want to
do all of this.
Suppose these display names where actually two
different people. For example, two different people in a
"Joe Bloggs" <email@example.com>
Suppose "Joe Bloggs" wants to subscribe to the Unix
newsletter. You probably wouldn't want the other "Joe" to be able to
unsubscribe. I know of a big support organization that is
set up this way. Everyone sees each other's email to this
support email address, but they are actually different people.
Maybe not the most practical example here, but this is something to
That's why I think it's easier just to leave it like
it is. When that user first subscribes, that's what
goes into the database, and the burdon is on the user
to keep using that same email, that's the way it is
Things seem to be working fairly well now, thansk for all your help...fingers crossed!
One little oddity, however. When an email comes in from hotmail and is forwarded through the script, the email received my list members looks like this:
As emailed previously we shall be holding the first Highland coaching panel= s sprint and slalom weekend this weekend 19/20 December. =20 Rules are basic=2C turn up in any boat=2C hire a faster boat yourself of if= you have none you can borrow either one of my liquid logic boats or one of= Mags pyrahna boats =20 Alternately sort out hiring a ICC wavehopper for the sprint day
=20 Tiings are registration is a 10am and we hope to be finshed by midday or 1p= m=2C to dish out medals and trophys. =20 Cost per race is =A35-00 adult =A32.50 child=2C proceeds towards improvemen= ts of the slalom course=2C and next years event. =20 Just bring your kayaking wear =20 Helpers - please turn up at the scout hall 9am on both days to meet me and = lend a hand. =20 Slalom gate ******************************** will be on thursday night at 6.30=2C bring a head torc= h and warm clothing=2C I shall have the gates and ladders. Meet at the cour= se. =20 Next year we can discuss having it earlier if folk want. =20 Oh - categories (trophies \ medals are for) =20 Under 12 Under 14 16 and Under=20 Adult 17 to 40 Vetrans - over 40 Masters - over 50 =20 remember its always easiet to get your name on the trophy first event coz i= ts smaller and less competitive. Thats my thoughts anyway. Helpers will hav= e time to compete. =20
Regards Steve Mackinnon Mobile 07775 682034 email firstname.lastname@example.org=20 =20"
Now, I'm sure the =20 and =A3 etc. symbols realting to formatting, but I can't for the life of me work out what format and how to covert it back into plain text while still retaining line breaks, carriage returns etc...any ideas?!
It looks like you've got some sort of character
encoding problem when it comes in from hotmail.
Let's see the path of where the mail goes.
Someone sends mail to your mail server.
your mail server receives it
individual.php gets it from the mail server.
individual.php processes it.
individual.php sends it out again.
someone's mail server receives it.
user get mail from that mail server.
Let's look at your mail server.
Your mail server should have an options section
where it allows you to configure settings.
Do you have a drop down menu called something like
It may include settings like this:
Mine is set to Unicode(UTF-8)
You may want to take a look at these settings
Let's look at the point where your individual.php
program reads it from the mail server.
This should be the line where is gets the mail
off the pop server.
$message = $pop->retr($id);
What is in $message?
Can you see what is in charset. It would be
something like charset="iso-8859-1" or
Do you see your characters in there like
the =2C or =A3 , or do you see the characters
There are a lot of postings on the net about hotmail
and character encoding issues. It looks like these
issues can be a lot of work.
As far as those characters go
In iso-8859-1 those characters map as follows
The 2C maps to comma
The A3 maps to British pound sign
I hope this helps to get you a little further along.
Many thanks as ever for your insightful comments...
Running the test as you suggest shows that the charsets for hotmail emails coming through is charset="iso-8859-1"...so, if those characters (2C, A3 etc.) are in that charset, why would they not display properly?
It seems to be a problem going right back to the message coming into the script from the mail server. Unless it's something in the POP3client.php script, then I think the issue may be mail-server-side?
I don't have control over the mail server settings as it's a shared host...if you think it might be this, I'll need to get on the phone to the host...
When I try British pound sign, it
does not work for me either.
In Hotmail, I typed in a British pound
sign by holding down alt and typing 1 5 6 on
the numeric keypad.
test case 1: passes
Hotmail -> my Web mail -> forward back to Hotmail
I send letter to my Web mail server with
the British pound sign in the message.
I read the mail on the web server and I see
the British pound sign.
From my Web server mail, I forward the mail
back to Hotmail (my web server has outgoing mail
configured to unicode(UTF-8). On Hotmail, I can
see the British pound sign.
So my web mail seems to be able to receive and send out
the British pound sign when it comes from Hotmail
test case 2: fails
Hotmail -> my Web mail server -> POP3client.php
In this case I don't see British pound sign on
the $message string.
In POP3client.php we are getting the message in
The function retr is using fgets to
put the message into the string, $message.
I am not clear on how the code is supposed to handle
the character encoding through here.
The code in the book gives a good basic
foundation for a mail system, but I am guessing
that getting it to work with European characters
would require more work.
I know that is not a solution for your problem, but
I did want to share my results concerning the mail
servers, maybe that will help to narrow it down.
I've managed to sort out the malformed characters problem...at least as it affects me...
Passing the $message string through quoted_printable_decode does the trick and sorts out the problem formatting...think it's maybe something to do with the message coming through in quoted-printable from hotmail etc. to ensure the integrity of the data (should the message pass through a character-translating, or line-wrapping gateway etc).
$message = quoted_printable_decode($message);
I placed this immediately after the message retrieval code...
// fetch message
$message = $pop->retr($id);
// convert any quoted-printable coding in message
&message = quoted_printable_decode($message);
Now I've got this sorted, the 'heavily amended' mailing list script appears to work ok...although future steps will be to enable it to handle attachments...a work in progress!
Thanks so much for all your help,
Last edited by daibhidh; January 8th, 2010 at 11:59 AM.
The Following User Says Thank You to daibhidh For This Useful Post: