Here is a problem that I have had for years now.  I have been trying to come up
with the perfect solution for this problem.  But, I have come down to two
different methods for solving it.

Here is the problem...

<?php

function sendEmail(
    $to,
    $from,
    $subject,
    $body,
    $attachments=array(),
    $headers=array()
    ) { # I typically do not put each argument on seperate lines, but I ran
        #out of width in this email...

    # do something here...
    mail(...);

}

sendEmail('j...@doe.com',
    'maryk...@uhhh.net',
    'Hi!',
    'Check out my new pictures!!!',
    $hash_array_of_pictures
    );

Now, we all have a function or method like this floating around somewhere.

My question is, how do YOU go about setting the required entries of the $headers
array() ?

I see three possible solutions.  I want to see a clean and simple solution.

Here are my ideas so far:

function sendEmail(
    $to,
    $from,
    $subject,
    $body,
    $attachments=array(),
    $headers=array()
    ) { # I typically do not put each argument on seperate lines, but I ran
        #out of width in this email...

    if ( empty($headers['Date']) ) {
        $headers['Date'] = date('c');
    }
    if ( empty($headers['Message-ID']) ) {
        $headers['Date'] = md5($to.$subject);
    }
    # and the example goes on...

    # do something here...
    mail(...);

}

Or, another example.  (I will keep it to the guts of the solution now)

    $headers['Date']       = empty($headers['Date']) ?
                             date('c') : $headers['Date'];
    $headers['Message-ID'] = empty($headers['Message-ID']) ?
                             md5($to.$subject) : $headers['Message-ID'];

OR, yet another example...

$defaults = array(
    'Date'       => date('c'),
    'Message-ID' => md5($to.$subject),
);

$headers += $defaults;

END of examples...

Now, IMO, the last one is the simplest one and for me, I think it will be the
new way that I solve this type of problem.

But, my question that I put out to all of you is...

        How would you solve this problem?

TIA

Jim Lucas

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to