is this function an effecient way to send mail?

Discussion in 'PHP' started by rlynch, Aug 9, 2006.

  1. #1
    function sendEmail($To, $From, $Subject, $Body)
    {
    global $set_ini_smtp, $quiet,$from_address_mail;

    mail("$To", "$Subject","$Body","From: $From <$From>\nX-Mailer: PHP 4.x\r\n\r\n");

    return true;
    }
     
    rlynch, Aug 9, 2006 IP
  2. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You are just doing a minor rewrite of the PHP mail function. I do not understand why you are including the globals. Unless you intend to use them you do not need them.

    I also question adding the X-Mailer bit and the extra newlines. By putting in two newlines you are forcing everything below that line to be part of the email message body and NOT the header. I would just use:

    function sendEmail($To, $From, $Subject, $Body)
    {
    mail($To, $Subject, $Body, "From: $From");
    return true;
    }


    Less is better in email headers.
     
    clancey, Aug 9, 2006 IP
  3. webviz

    webviz Peon

    Messages:
    216
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    <?php
    
    function send_email($to, $subject, $message, $headers)
    {
         // you may care to do some regex to filter out any sent shit
    
        mail($to, $subject, $message, $headers);
    
        return true;
    }
    
    ?>
    
    PHP:
     
    webviz, Aug 9, 2006 IP
  4. casper

    casper Guest

    Messages:
    181
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I use SourceForge phpmailer. I own a mailform processor and I noticed that the mail function didn't always send my emails out when sending loads of emails.
     
    casper, Aug 10, 2006 IP
  5. talentcoder

    talentcoder Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The function mail() just puts your email in the queue of mail server (MTA). When your email will be sent out depends on how the queue is running. So the most effecient way of sending mail is to run the queue frequently. It doesn't matter how you code in PHP.
     
    talentcoder, Aug 11, 2006 IP
  6. ravianz

    ravianz Notable Member

    Messages:
    1,536
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    250
    #6
    mail function dewscribed by clancey is perfect and i have been using it in same way for a long time!
     
    ravianz, Aug 11, 2006 IP