PHP / Sendmail / SMTP - Page 2

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Re: PHP / Sendmail / SMTP

Richard wrote:
Quoted text here. Click to load it

Just treating someone who can't even trim properly delineated sigs (and
doesn't know how to make his own sig separator correctly) in a way he

You definitely don't understand anything technical.  But then I guess
that's why you and TNP get along so well.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: PHP / Sendmail / SMTP

Quoted text here. Click to load it
Good Lord, don't *either* of you guys know how to trim a post? :-)

Re: PHP / Sendmail / SMTP

Richard wrote:
Quoted text here. Click to load it
WEll I missed that since Jerry is in my kill file.

As usual, all he thinks about is lazy programming. He missed the point
about what the actual architecture of an MTA is and why it is in many
ways advantageous.

Of course, you can do both, and use the Pear package to talk to a local
MTA on the local machine itself.

Then if you consider the few hours of code to add e.g. attachments to
your own Mail library to be less hassle than downloading, installing,
and reading the documentation on the PEAR mail package, not to mention
any extra CPU cycles it takes, you probably get the best of both worlds.
Or the worst, depending on your point of view.

I found code to send attachments very quickly and had a simple 'send
mail with an attachment' going in less than 4 hours.

Its hardly rocket science.

Although its beyond Jerry.

Here it is.

function mail_pdf_file($email,
    $attach=chunk_split( base64_encode($buf));
    $boundary = md5( time() );
    $headers = sprintf("From: %s\nMIME-Version: 1.0\nContent-Type:
multipart/related; boundary=\"%s\"",
                $from, $boundary);
     $message = sprintf("--%s\nContent-Type: text/plain;
7bit\n\n%s\n\n--%s\nContent-Type: application/pdf;
name=\"%s\"\nContent-Disposition: attachment;
filename=\"%s\"\nContent-Transfer-Encoding: base64\n\n%s\n\n--%s--\n",
      $boundary,$body,$boundary,$filename, $filename,$attach,$boundary);
      mail($email, $subject, $message, $headers, "-f ".$return_path );

Re: PHP / Sendmail / SMTP

Richard wrote:
Quoted text here. Click to load it

Possibly because they aren't clueful at setting up the hosts mail
system. Or dont have access to it.

Quoted text here. Click to load it

Though wry, my comment is pretty accurate. No one uses windows for
multiuser systems. at best its a one function server administered by one
person. Windows was never designed as a multi-user system. it doesn't
even have the concept of multiple screens attached to a single  CPU. It
was a long time before it had even pre-emptive multi-tasking. (NT and
its derivatives IIRC)

The clue is in the name 'personal computer' One user, one CPU.

Windows started out to give the best personal experience to a user. *nix
started out to serve many users efficiently. *nix has done slightly
better at giving a decent 'personal' experience to a single user, than
Windows has in becoming a multiuser system. Even today it only really
wporks as a file or web server, not an application server, because it
has no concept AFAIK of separate SCREENS and KEYBOARDS as potential
input and output devices that are attached to different processes.
Neither it needs to be said, does an Apple.

X-windows, the *nix windowing system, whilst hugely overkill for a
single user, does.

Anyway the point is to highlight the history and features of these
systems, to answer the question.

*nix has always had some kind of centralised multiuser mail forwarding
agent in it: It needed to. And its whole philosophy was originally cost
effective Central management of resources by a sysadmin.

Windows never had mail at all. since PCs were standalone systems, there
wasn't much point. Microsoft mail as first incarnated used shared file
servers to exchange email amongst a workgroup ONLY. There never was an
'official' microsoft MTA until Exchange, and that was never intended to
run on a users PC. It ran on an NT server. And it was based on the
perceived need for intra organisation X-400 mail. Not Internet Mail.
That was tacked on as a kludge on the side. I actually was paid to
assess exchange. And sadly, because at the time we made a lot of money
selling and installing MTAs, I had to honestly conclude that somehow
Microsoft had indeed managed to get someone to write a pretty decent bit
of code. It was a lot beter than the NT it ran on, let's put it that way.

So MTA's have never been part of a single PeeCee. Hence the need to
fudge something at the PHP level to turn a standalone personal computer
into a mail sender and web server.

So, there is no reason to go complex mailer wise on a *nix system,
unless you want to present e/g. a simplified OOP interface to the
programer, or for some reason bypass the *nix mail system. You might
well do that if you are operating at a level where you are connecting to
an ISP that uses verified SMTP transfers. Setting that up is not so
simple with most *nix MTA's since their legacy is from trusted mail
systems. I've personally not needed to do that, because the ISP's I use
are happy to accept unauthenticated e-mail from their own IP space. It
can be done, but its not always that simple.

there isn't a lot of difference at one level (coding level) between a
PHP process opening a call to a local or remote port 25 and doing a
simple SMTP transfer, and exec'ing a mail process to do it for you.

At another level, there is. Consider the case where a large transfer to
a busy server takes place. With a *nix system, you invoke sendmail (or
some clone thereof) which immediately accepts your mail, queues it, and
forks a background process to attempt to send it. But once its queued,
your program that invoked it, can finish. It can exit and the PHP script
terminates. User sees snappy response.

IF the PHP is sending directly, it can't finish until the entire message
has been sent to the next hop MTA. That is the problem with no local
MTA. How do you cope with a relay that is temporarily down. You cant best you can time out and return an error message.

Which is what the PEAR  mail package does. As far as I can tell. I dont
use it. So knowledge is from its documentation.

PEAR_MAIL_SMTP_ERROR_CONNECT means it couldn't connect to the designated
SMTP server.

So, you have a simple choice. Bypass the *nix mail system, and encounter
issues with mail that can't be relayed instantly, but have all teh
issues of SMTP authorisation immediately soluble inside a PHP
environment,  or get to grips with understanding the local MTA on your
system, and use it intelligently.

Because I made a living out of setting up  *nix MTA's for several years,
my personal choice is the latter. I've just rebuilt my server here after
a crash. It needs to have a way to send me operating system errors, so
its mail has to work. So now it does work, it works also for PHP. No
need for PEAR mail


I hope that provides the answer you wanted.

Re: PHP / Sendmail / SMTP

Quoted text here. Click to load it

Only one of the last paragraphs told me something usefull, thanks for

(The rant about Windows is still silly.
Seems you had a look at it in the 80-ies, and think it is still the

Anyway, lets leave it here.


Re: PHP / Sendmail / SMTP

Richard wrote:
Quoted text here. Click to load it

Oh dear. I have been scrupulously fair to windows.

It was designed to be something other than *nix. It has different
strengths and weknexssxes.

I explained why a local queing MTA is  on *nix, and not on windows, and
why its a better choice than using a remote SMTP relay.

If that doesn't answer your questions, then I am not sure why you asked.

Next time ask a more precise question.

Re: PHP / Sendmail / SMTP

Quoted text here. Click to load it

The question was:

Quoted text here. Click to load it

That was the whole question and nothing but the question.

Thanks anyway.


Re: PHP / Sendmail / SMTP

Richard wrote:
Quoted text here. Click to load it
And I came up with one possible answer:

because you are too lazy to program the mail call, or to learn how to
set up the *nix system, correctly.

Quoted text here. Click to load it

Re: PHP / Sendmail / SMTP

Ben Humpert wrote:
Quoted text here. Click to load it

If I recall correctly (and I tried this in the past and got it to work),
you give a path to sendmail in php.ini. If you create a batch file (for
instance in PHP) that accepts the sendmail parameters, you can basically
intercept the sending of mail through the mail() function and do with it
whatever you like. This can be handy on a development machine to test if
mail would be sent without actually sending it.

Re: PHP / Sendmail / SMTP

El 04/02/2010 18:57, Ben Humpert escribió/wrote:
Quoted text here. Click to load it

The bundled mail funcionality has different implementations depending on
the platform. Unix uses sendmail and doesn't support SMTP, Windows uses
SMTP and doesn't support sendmail.

So you are basically asking why Unix doesn't support SMTP. Well, I guess
that nobody took the work of writing the code to implement it, probably
because the sendmail binary is a basic tool in Unix systems, almost as
standard as "ls" or "vi".

Two remarks:

- That requirement only applies to the built-in mail() function. As
you've been told, there're many third-party libraries that implement
other methods.

- You can configure your local mail system to serve as a relay for an
external SMTP server. It doesn't need to accept incoming connections.
Just think of it as a support library. Furthermore, it's worth doing
because many other tools beyond PHP can leverage this feature (for
instance, cron can report failed tasks via e-mail).

-- - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
-- Mi web de humor satinado:

Site Timeline