php-general Digest 12 Oct 2006 16:23:58 -0000 Issue 4397
Topics (messages 243015 through 243028):
Re: PHP Mailer and SMTP = SPAM?
243015 by: Peter Lauri
243028 by: Richard Lynch
Re: OOP slow -- am I an idiot?
243016 by: Stut
243017 by: Roman Neuhauser
243018 by: Tony Marston
243023 by: Chris de Vidal
PHP causing seg fault
243019 by: Glenn Richmond
243025 by: Kristen G. Thorson
243027 by: Richard Lynch
Re: PHP 5 Hosting
243020 by: Sancar Saran
Re: If array()
243021 by: Max Belushkin
Re: foreach
243022 by: Jochem Maas
php mailer problem
243024 by: Ross
243026 by: Richard Lynch
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
php-general@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
[snip]
Unless the email is coming "from" somebody the recipient knows/trusts,
then you're going to get marked by them as a spammer -- which will
report back to some of the lists marking you as a spammer.
[/snip]
But is it not a problem sending from the SMTP server thedomain.com using
something else then the email [EMAIL PROTECTED] I am planning to send
from an existing email from the domain.
So even that I send from thedomain.com SMTP server I should to set the FROM
and REPLY TO to the person who is referring? Our main idea was to send the
email from the author of the book as it comes from him, but that is maybe
not a great idea?
So I am in the middle of two suggestions:
1. Make sure that the email is in the domain that you are sending from
2. Make sure that the emails is from the referring persons email so it won't
be marked as spam at their point.
This is what I got from "Rick". What are you thoughts on this?
[snip]
when you do a dns lookup (from a machine not on the same network) on the
ipnumber of the sending mail server does it show a name? if you do a forward
lookup on that name, does that resolve to the (same) ipnumber?
the answer to the first part must be "yes", and ideally the second will be
"yes". if the first is "no", then don't bother sending from that machine
until that issue has been dealt with.
sending html substantially increases the probability that your messages will
be tagged as spam. certain things will increase that probability.
your point "2." is mostly irrelevant. an smtp server simply needs to be
configured so it is not an open relay. that is generally the default
configuration (of any MTA that's worth using), and is achievable without
smtp auth.
[/snip]
Best regards,
Peter Lauri
www.lauri.se - personal website
www.dwsasia.com - company website
--- End Message ---
--- Begin Message ---
On Wed, October 11, 2006 11:28 pm, Peter Lauri wrote:
> [snip]
> Unless the email is coming "from" somebody the recipient knows/trusts,
> then you're going to get marked by them as a spammer -- which will
> report back to some of the lists marking you as a spammer.
> [/snip]
>
> But is it not a problem sending from the SMTP server thedomain.com
> using
> something else then the email [EMAIL PROTECTED] I am planning to
> send
> from an existing email from the domain.
Not really -- at least not in my limited experience.
There are so many OTHER factors that the DNS resolution of the return
address and the actual SMTP machine not matching up are probably not a
deciding factor...
I could be wrong on this -- I don't run SMTP servers, and *most* of my
email is coming out from the same server, but I also have a "contact
them" link, and it seems to work fine, and is most certainly not using
return addresses whose DNS matches the sending server.
> So even that I send from thedomain.com SMTP server I should to set the
> FROM
> and REPLY TO to the person who is referring? Our main idea was to send
> the
> email from the author of the book as it comes from him, but that is
> maybe
> not a great idea?
Send the email "From: " the person who actually typed it.
Anything else is more likely to trip you up in some other way, I
should think.
> So I am in the middle of two suggestions:
>
> 1. Make sure that the email is in the domain that you are sending from
> 2. Make sure that the emails is from the referring persons email so it
> won't
> be marked as spam at their point.
In an ideal world, you have a limited number of authors, and you can
configure YOUR SMTP server as a relay for them, thus meeting both
conditions.
rasmus AT dwsasia.com would a valid email, forwarding to a known valid
email for Rasmus the PHP Pocket Guide author.
So, you get the best of all worlds -- Custom emails on your site with
the correct DNS resolution to "match" the sender, the author's name in
the email address, even using the "First Last" <[EMAIL PROTECTED]>
format.
This satisfies all the conditions, at the minimal expense of setting
up an email forward for each author/recipient.
If I had easy access to control email setup, I'd do that on my site,
but I don't, so I just send them out with the return address of
whomever sent them.
Course I also throttle it so it can only send 4 emails per day from
one IP, and have a few other measures in place to limit spam abuse.
NOTE:
If the authors aren't typing the actual email, you do NOT want to be
sending it "from" them without their prior explicit review and consent
of the outgoing email. Authors in particular are very picky about
what words you put in their mouth. :-)
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
Roman Neuhauser wrote:
# [EMAIL PROTECTED] / 2006-10-11 21:28:36 +0100:
Richard Lynch wrote:
On Tue, October 10, 2006 6:14 pm, Chris de Vidal wrote:
I want to create a "customer" class which fetches its attributes from
a MySQL database.
No, you don't. :-)
This is a classic example of the "obvious" OOP solution being wildly
inappropriate.
Ok, so I now find myself in the unusual position of disagreeing with the
Lynchmeister. Why is this wildly inappropriate? IMHO this is what OOP is
all about.
No, that's what trivial OOP examples applied to the letter where
a different approach is in order are. If you study the GoF book [GoF]
you'll see that the traditional claim "objects model physical
entities from real world (and nothing else)" is very simplistic
and terribly limiting.
[GoF] http://www.amazon.com/dp/0201633612/
If you paint yourself into this corner you'll find your code
grinding the database to death in the OO-relational impedance
mismatch. The OOP ideal of a single source of data is nice,
unfortunately the real world gets in the way.
I never said anything about physical entities. The OOP methodology has
nothing to do with physical entities, but it has everything to do with
entities. The fact that in this example the entity is physical has no
bearing on it whatsoever. Nobody said anything about limiting OOP
entities to physical entities.
You can encapsulate everything to do with a customer in an object. This
ensures that you don't duplicate any code that works on customer data.
You avoid duplication of code. As a result you can ensure data integrity
because there is only one route to read and write it.
Who talks about duplicating business logic? You just need to have
more than one access point for the data.
If you have more than one access point for the data you end up with a
more complicated maintenance situation since you may have several places
that treat the data differently. This is bad m'kay.
When you're talking about something as simple as a customer it's true
that an OOP approach probably doesn't add much to the equation. However,
when you're dealing with complex entities which span several tables and
have data stored in a different format to how it's used (think
serialize) it makes sense to have a single point where you can get that
data so that you don't end up duplicating the code needed to extract and
store it.
If this is not what you think OOP is all about, do please enlighten us
as to the error of our ways.
Imagine deleting many rows in a table one by one (pseudocode):
<snip>
instead of taking them with a single DELETE:
<snip>
Whoa nellie!! This is a question of design, not a question of whether to
use OOP. For example, in several of the sites I maintain I have classes
that inherit from a base class called Table. The base class provides a
lot of the basic methods for working on a table (think ActiveRecord). It
also has static methods for doing things like updates and deletes based
on a where clause. The derived classes can override filter methods
(AfterLoad and BeforeSave) to massage the data after it's loaded and
before it's saved. They also add any methods needed for acting on that
particular entity.
I'm the first to admit that OOP is not always the best methadology to
use - the 'best methadology for all situations' does not exist. However,
the general feeling people will get towards OOP from this list seems to
be 'OOP bad, anything else better'. OOP is great as long as you follow
OOD principles and have a fair amount of common sense. It should not be
used just because it's there, but it should also not be dismissed.
In fact, in writing that I've just realised that OOP is not the key...
OOD is. OOD can be applied (with no syntax or compiler assistance) in a
functional system which will have great benefits, all of which I think
most people are aware of but, for whatever reason, fail to adequately
apply - which is where OOP can be useful since it enforces the structure
and protection through the syntax (PHP4 sucked for this, PHP5 is better).
When you actually think about it, OOP is not a methadology - it's a
syntax. OOD is the methadology. Ramble... ramble... ramble... over!
-Stut
--- End Message ---
--- Begin Message ---
# [EMAIL PROTECTED] / 2006-10-12 06:49:22 +0100:
> Roman Neuhauser wrote:
> ># [EMAIL PROTECTED] / 2006-10-11 21:28:36 +0100:
> >>Richard Lynch wrote:
> >>>This is a classic example of the "obvious" OOP solution being wildly
> >>>inappropriate.
> >>Ok, so I now find myself in the unusual position of disagreeing with the
> >>Lynchmeister. Why is this wildly inappropriate? IMHO this is what OOP is
> >>all about.
[...]
> I never said anything about physical entities. The OOP methodology has
> nothing to do with physical entities, but it has everything to do with
> entities. The fact that in this example the entity is physical has no
> bearing on it whatsoever. Nobody said anything about limiting OOP
> entities to physical entities.
Right, sorry for going off on a tangent, it was 3am. :]
> When you're talking about something as simple as a customer it's true
> that an OOP approach probably doesn't add much to the equation. However,
> when you're dealing with complex entities which span several tables and
> have data stored in a different format to how it's used (think
> serialize) it makes sense to have a single point where you can get that
> data so that you don't end up duplicating the code needed to extract and
> store it.
I'll have most of that handled by the database through triggers,
updatable views, foreign keys etc.
> >>If this is not what you think OOP is all about, do please enlighten us
> >>as to the error of our ways.
> >
> > Imagine deleting many rows in a table one by one (pseudocode):
> <snip>
> > instead of taking them with a single DELETE:
> <snip>
>
> Whoa nellie!! This is a question of design, not a question of whether to
> use OOP.
Sure. I think "obvious" is the key word in Richard's statement:
> >>>This is a classic example of the "obvious" OOP solution being wildly
> >>>inappropriate.
AFAICS he says that the "obvious" solution is wrong, not that OOP
is wrong here.
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
--- End Message ---
--- Begin Message ---
"Roman Neuhauser" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
># [EMAIL PROTECTED] / 2006-10-11 21:28:36 +0100:
>> Richard Lynch wrote:
>> >On Tue, October 10, 2006 6:14 pm, Chris de Vidal wrote:
>> >>I want to create a "customer" class which fetches its attributes from
>> >>a MySQL database.
>> >
>> >No, you don't. :-)
>> >
>> >This is a classic example of the "obvious" OOP solution being wildly
>> >inappropriate.
>>
>> Ok, so I now find myself in the unusual position of disagreeing with the
>> Lynchmeister. Why is this wildly inappropriate? IMHO this is what OOP is
>> all about.
I have to disagree as well. There is absolutely nothing wrong which the
approach of creating one class for each table in the database. It cannot be
wrong for the simple reason THAT IT WORKS! It is also the simplest approach
as it keeps all the business rules for each database entity in a single
class. Also, by keeping the structure of each object in sync with the
structure of the database you don't have to introduce another pointless
level of complexity with OR mappers.
Those OO "purists" who insist on creating object hierarchies which bear no
resemblance to the database structure are making a rod for their own backs.
That notion of "purity" is my idea of "putrefaction".
--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
--- End Message ---
--- Begin Message ---
By the way, about myself. I'm primarily a system administrator. Most of the
time I USE code, NOT
write it. But I also dabble, and right now we need to improve our old custom
PHP revenue
application which has sat stagnant for a few years. We can't afford a
full-time programmer and I
know enough to be dangerous ;-) So I'm the guy.
All that to say I'm no pro and am humbly asking your collective professional
opinions.
--- Richard Lynch <[EMAIL PROTECTED]> wrote:
> > I want to create a "customer" class which fetches its attributes from
> > a MySQL database.
>
> No, you don't. :-)
>
> This is a classic example of the "obvious" OOP solution being wildly
> inappropriate.
I'll consider that possibility.
> Start thinking more in terms of what you want the whole application to
> do, and build classes that do THAT, rather then starting with a single
> customer and their info.
It seems you are advocating procedural programming here. I don't see how your
use of classes are
anything more than glorified functions. I could re-word the sentence above
thusly:
> Start thinking more in terms of what you want the whole application to
> do, and build [functions] that do THAT...
That's the path we went down at first and the net result was data access
functions being copied
and modified all over the place, making maintenance a real chore.
Did it have speed? Yes. Do I hesitate to make changes to it? Yes. In a
world where I am forced
to choose between speed and maintainability, I'll probably choose speed,
particularly when the
program will be used daily. However, I truly believe a speedier OOD is
attainable, which is why
I'm asking.
If, however, you are talking about some blending, where I create a
procedural-style class and then
make any modifications in subclasses which override the parent class, like this:
class parentFunction
{
getRevenueForCustomer ($id)
{
// SELECT * FROM customer_revenue WHERE customer_id = '$id'
}
}
class childFunction inherits parentFunction
{
// Overriding the parent function
getRevenueForCustomer ($id, $year, $month, $department)
{
// SELECT * FROM customer_revenue WHERE customer_id = '$id' AND year =
'$year' AND month =
'$month' AND department = '$department'
}
}
If that's what you mean, I honestly can't see how that saves coding time or
helps maintenance,
unless I need to also use some extraneous code with every query which would be
included into the
constructor. But then I could also use a function (instead of a class) which
is like a query
wrapper:
function sql_query ($query)
{
// Some massaging routines
// ...
// Some more
// ...
$result = mysql_query ($query);
// Error handling routines
// ...
// Other routines
// ...
return $result;
}
sql_query ("SELECT * FROM ...");
If that's the case, I don't see the need for classes at all, and that's
actually the path we went
down at first. We created a query function which massaged the input and
handled errors. I've
since learned that's not what I really wanted to do; I want to handle errors
elsewhere. I think
the above is easier to understand than using a class.
Anyway, tell me what you have in mind.
CD
Think you're a good person? Yeah, right! ;-)
Prove it and get ten thousand dollars:
TenThousandDollarOffer.com
--- End Message ---
--- Begin Message ---
Hi guys,
I'm attempting to run a SugarCRM variant that uses SOAP to access
information from the database. The code is causing a seg fault when
executing a particular line of code. The code executes properly until it
calls a generic function in the parent class that causes a seg fault on
the return command. The line of code is:
return $this;
I've found this to be a problem in PHP version 5.1.4 and 5.2.0rc4. Is
this statement illegal in PHP5? When I set a memory limit for the
script, the error changes to indicating that it has exceeded its memory
allocation, so it seems to be allocating memory over and over.
Note that this code runs fine on most other combinations of functions
calling this same parent method. Any suggestions are appreciated.
Thanks,
Glenn.
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Glenn Richmond [mailto:[EMAIL PROTECTED]
> Sent: Thursday, October 12, 2006 4:45 AM
> To: php-general@lists.php.net
> Subject: [PHP] PHP causing seg fault
>
> Hi guys,
>
> I'm attempting to run a SugarCRM variant that uses SOAP to access
> information from the database. The code is causing a seg fault when
> executing a particular line of code. The code executes properly until
it
> calls a generic function in the parent class that causes a seg fault
on
> the return command. The line of code is:
>
> return $this;
>
> I've found this to be a problem in PHP version 5.1.4 and 5.2.0rc4. Is
> this statement illegal in PHP5? When I set a memory limit for the
> script, the error changes to indicating that it has exceeded its
memory
> allocation, so it seems to be allocating memory over and over.
>
> Note that this code runs fine on most other combinations of functions
> calling this same parent method. Any suggestions are appreciated.
This sounds a lot like what I was running into. What is the OS? I was
having a very similar-sounding problem running SugarCRM on any Red Hat
system (including CentOS and Fedora).
kgt
--- End Message ---
--- Begin Message ---
On Thu, October 12, 2006 3:44 am, Glenn Richmond wrote:
> I'm attempting to run a SugarCRM variant that uses SOAP to access
> information from the database. The code is causing a seg fault when
> executing a particular line of code. The code executes properly until
> it
> calls a generic function in the parent class that causes a seg fault
> on
> the return command. The line of code is:
>
> return $this;
>
> I've found this to be a problem in PHP version 5.1.4 and 5.2.0rc4. Is
> this statement illegal in PHP5? When I set a memory limit for the
> script, the error changes to indicating that it has exceeded its
> memory
> allocation, so it seems to be allocating memory over and over.
>
> Note that this code runs fine on most other combinations of functions
> calling this same parent method. Any suggestions are appreciated.
Are you sure you are not causing an infinite loop or a circular data
reference that PHP is attempting to iterate through?
It sure *sounds* like that might be the case, from the symptoms
presented.
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
--- End Message ---
--- Begin Message ---
take look
www.site5.com
On Thursday 12 October 2006 00:59, Ed Lazor wrote:
> Anyone ever use A2Hosting.com? Or better yet, any recommendations on
> a PHP 5 web hosting company that you're happy with - measured in
> terms of quality support, they know what they're doing, and they have
> good prices? Bonus points for good drive space, bandwidth, and SSH
> access.
>
> I ran a Google search and came up with several options.
> A2Hosting.com seems the best so far. My only reservation is that
> they offer 24/7 support through a message service who will page a
> tech who in turn will call you back - seems sketchy and I can imagine
> trying to talk someone into going to the server room at 2am. I also
> checked out many of the other options, but some of them seemed even
> more sketchy... like VisualWebHosting.com... you click on their link
> for a BBB review and it brings up another company entirely... and you
> call their number and all the greeting says is "Please leave a
> message... beeeeeeeeep"... pretty scary if you ask me.
>
> Anyway, thanks in advance for any recommendations you have.
>
> -Ed
--- End Message ---
--- Begin Message ---
John Taylor-Johnston wrote:
How can I use "if" to see an array contains something?
if (sizeof($array)) ?
--- End Message ---
--- Begin Message ---
João Cândido de Souza Neto wrote:
> Hello.
>
> In the follow code:
>
> $numbers=array(1,2,3,4,5);
> foreach ($numbers as number) {
> ...
> }
>
> Inside foreach, could i know if i am in the last element of the array
> $numbers?
you've already had a few alternatives; how about this:
foreach ($numbers as $key => $number) {
// loopy stuff
}
// do something special with the last item (and it's key?)
// which will currently be stored in $number and $key respectively
// e.g. :
processWhateverTheLastElementWas($numbers[ $key ]);
// or :
processWhateverTheLastElementsValueWas($number);
basically immediately after the foreach loop you have the key and value
of the last element - chances are you therefore have what you need to do what
you need. no?
>
--- End Message ---
--- Begin Message ---
Why does this send multiple times. I want it to loop through and send it
once.
-----------------------------------------------------------------------------------------
<?php
session_start();
include "check_login.php";
global $PHP_SELF, $mail_text, $search_string;
if(!isset($_POST['area'])){ $_POST['area']='a'; $area= $_POST['area'];}
if(!isset($_POST['filter'])){ $_POST['filter']="sname"; $filter =
$_POST['filter'];}
if (isset($SUBMIT)){
$mail_body = "this is the body";
include("mailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->Mailer = "mail";
// telling the class to use SMTP
$mail->IsHTML(true);
$mail->Host = "mail.scottishsocialnetworks.org"; // SMTP server
$mail->FromName = "Scottish Social Networks";
$mail->From = "[EMAIL PROTECTED]";
//set up the mail loop
$addresses = array();
$addresses = explode(",", $mail_to);
$mail->AddAttachment($userfile, $_FILES['userfile']['name']);
$mail->Subject = $mail_subject;
$mail->Body = nl2br($mail_body);
$mail->WordWrap = 50;
for($i = 0; $i < count($addresses); $i++)
{
$mail->AddAddress($addresses[$i]);
$mail->Send();
}
}
?>
<?php
//include ('authorise.php');
include ('connect.php');
global $one, $two, $three, $recipients, $people;
$query= "SELECT * from $table_name WHERE $filter LIKE '%$search_string%'";
$area= $_POST['area'];
if ($area=="a") {
$query .=" AND area LIKE '%%'";
}
else {
$query .=" AND area='$area'";
}
$result = mysql_query($query);
$query .= " ORDER BY sname";
$result = mysql_query($query) or die('Error, query failed');
while ($row=mysql_fetch_array($result)) {
$email_addresses[] = $row['email'];
$count = count($email_addresses);
$recipients = implode(', ', $email_addresses);
//this counts the number of entries
//echo $count;
//echo $recipients;
}
if (isset($SUBMIT)) {
if (empty($mail_to)){
?>
<script>
alert ('You have not entered the recipients email address')
</script>
<?
}
else {
?>
<script>
alert ('Your email has been sucessfully sent')
</script>
<?
}
}
?>
--- End Message ---
--- Begin Message ---
Move the ->Send outside the loop?
And fix your indentation to something sane, so you know what's going
on in your script.
[Apologies if mail transport messed it up...]
On Thu, October 12, 2006 8:30 am, Ross wrote:
> Why does this send multiple times. I want it to loop through and send
> it
> once.
>
>
> -----------------------------------------------------------------------------------------
> <?php
> session_start();
> include "check_login.php";
>
> global $PHP_SELF, $mail_text, $search_string;
>
> if(!isset($_POST['area'])){ $_POST['area']='a'; $area=
> $_POST['area'];}
>
> if(!isset($_POST['filter'])){ $_POST['filter']="sname"; $filter =
> $_POST['filter'];}
>
>
>
> if (isset($SUBMIT)){
>
> $mail_body = "this is the body";
>
> include("mailer/class.phpmailer.php");
>
> $mail = new PHPMailer();
> $mail->Mailer = "mail";
> // telling the class to use SMTP
> $mail->IsHTML(true);
> $mail->Host = "mail.scottishsocialnetworks.org"; // SMTP server
> $mail->FromName = "Scottish Social Networks";
> $mail->From = "[EMAIL PROTECTED]";
>
> //set up the mail loop
>
>
>
>
> $addresses = array();
> $addresses = explode(",", $mail_to);
>
> $mail->AddAttachment($userfile, $_FILES['userfile']['name']);
> $mail->Subject = $mail_subject;
> $mail->Body = nl2br($mail_body);
> $mail->WordWrap = 50;
>
> for($i = 0; $i < count($addresses); $i++)
> {
> $mail->AddAddress($addresses[$i]);
> $mail->Send();
>
> }
>
>
>
>
>
>
>
>
> }
>
>
>
>
>
>
>
>
>
>
> ?>
>
>
> <?php
> //include ('authorise.php');
> include ('connect.php');
> global $one, $two, $three, $recipients, $people;
>
>
>
>
>
>
>
>
>
>
>
> $query= "SELECT * from $table_name WHERE $filter LIKE
> '%$search_string%'";
>
>
> $area= $_POST['area'];
>
>
> if ($area=="a") {
> $query .=" AND area LIKE '%%'";
> }
> else {
> $query .=" AND area='$area'";
> }
>
>
>
> $result = mysql_query($query);
>
>
> $query .= " ORDER BY sname";
>
>
>
>
> $result = mysql_query($query) or die('Error, query failed');
> while ($row=mysql_fetch_array($result)) {
>
> $email_addresses[] = $row['email'];
>
>
> $count = count($email_addresses);
> $recipients = implode(', ', $email_addresses);
> //this counts the number of entries
>
> //echo $count;
> //echo $recipients;
> }
>
> if (isset($SUBMIT)) {
> if (empty($mail_to)){
> ?>
> <script>
> alert ('You have not entered the recipients email address')
> </script>
> <?
> }
> else {
> ?>
> <script>
> alert ('Your email has been sucessfully sent')
> </script>
> <?
> }
> }
> ?>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
--- End Message ---