#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    10
    Rep Power
    0
    I started off using PHP's mail() function, and it worked great exept for the fact that it took way to long to execute. I came across the following sendmail() function at phpbuilder.com This function works perfect except for the fact that I can't send header info. I was told that in order to send HTML mail, you need to specify in the header, the content-type & such.

    Question is: How can I send header info in this script ? I need to send HTML mail

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?


    #################################################################
    /*
    I hope you find this usefull *I sure did*
    I'm still working on adding mime support.
    Created:
    Sun Aug 13 07:18:10
    Anyquestions?
    e-mail:
    meyowith@home.com
    */

    /*
    Version 1.2.1
    Revised by Benjamin Smith
    to fix some bugs pertaining to "silent mode" - see setting $verbel below.
    -BDS 08/20/00
    bens@saber.net
    */

    /* Version 1.2.2
    Revised by slliid
    The previous version did not properly send the message body to the SMTP server.
    08/24/00
    slliid@hotmail.com
    */

    Class Pop {

    // global varibles

    Var $smtp_server = "";
    Var $smtp_user = "";


    Var $mailTO = "";
    Var $mailFrom = "";
    Var $mailSubject = "";
    Var $mailText = "";


    Var $deadmsg = "";
    Var $verbel = "0";
    //Modify this for verbose output of the transaction..
    //1 for verbose
    //0 for silent

    //all these varibles can be set directly without calling the procedures,
    //this just makes it simple

    Function serverInfo($in_SERVER="mail.nimc1.on.home.com", $user_SERVER="me"){
    $this->smtp_server = $in_SERVER;
    $this->smtp_user = $user_SERVER;
    }

    Function setText($in_SUBJECT, $in_TEXT){
    $this->mailSubject = ereg_replace("n"," ",$in_SUBJECT);
    $this->mailText = $in_TEXT;
    }

    Function setFrom($in_TO, $in_FROM){
    $this->mailTO = $in_TO;
    $this->mailFrom = $in_FROM;
    }


    //the main sending function..hopefully not as buggy as the original "sendmail"

    Function sendmail(){
    //make sure the user entered everything..don't want to be spamming
    if(trim($this->mailSubject) != ""){

    } else {
    $this->deadmsg .= " A subject. Please enter a subject.n";
    }
    if(trim($this->mailText) != ""){

    } else {
    $this->deadmsg .= " Any data. Please enter some..n";
    }

    if(trim($this->mailTO) != ""){
    } else {
    $this->deadmsg .= " A valid send-to address..n";
    }
    if(trim($this->mailFrom) != ""){
    } else {
    $this->deadmsg .= " A valid recepient..n";
    }
    //if the user has entered something wrong
    //it gets trapped out to the "End()" procedure
    if ($this->deadmsg != ""){
    $this->end();
    }
    //else..
    $server = $this->smtp_server;

    $smtp_sock = fsockopen($server, 25, &$errno, &$errstr, 30);
    if (!$smtp_sock) {
    echo "error...!!n";
    echo "$errstr ($errno)<br>n";
    } else {
    while (!feof($smtp_sock)){
    fputs($smtp_sock, "HELO ".$this->smtp_server."rn");
    $this->echos($smtp_sock,4096,$this->verbel);
    fputs($smtp_sock, "MAIL FROM:<".$this->mailFrom.">rn");
    $this->echos($smtp_sock,4096,$this->verbel);
    fputs($smtp_sock, "RCPT TO:<".$this->mailTO.">rn");
    $this->echos($smtp_sock,4096,$this->verbel);
    fputs($smtp_sock, "DATAn");
    $this->echos($smtp_sock,4096,$this->verbel);
    fputs($smtp_sock, "From: ".$this->mailFrom."nSubject: ".$this->mailSubject."nTo: ".$this->mailTO."nn".$this->mailText."n");
    $this->echos($smtp_sock,4096,$this->verbel);
    fputs($smtp_sock, "rn.rn");
    $this->echos($smtp_sock,4096,$this->verbel);
    fputs($smtp_sock, "quitn");
    }
    if ($this->verbel==1)
    {
    echo "<pre>";
    echo "nnsending mail from..". $this->mailFrom ."n";
    echo "to.................". $this->mailTO ."n";
    echo "saying.............". $this->mailSubject ."n";
    echo " ". $this->mailText ."n";
    echo "Done n";
    echo "</pre>";
    }
    fclose($smtp_sock);
    }
    }

    Function echos($pipe_IN, $size=4096, $print){ //play with this buffer if your connections slow
    if ($print == 1){
    echo nl2br(fgets($pipe_IN, $size)); //modifyed command for prettyness
    } else {
    nl2br(fgets($pipe_IN, $size)); //Sent to the bit bucket or this function hangs here.
    //silent..
    }
    }


    Function end(){
    echo "<pre>n";
    echo "You have failed in these following places..n";
    echo $this->deadmsg; //echo the collected msgs's
    echo "</pre>n";
    exit; //This can be deadly..remove if you are having unexplained "exits"
    }
    }


    /*
    $mail = new Pop; //Initiate new class..

    $mail->serverInfo("mail.nimc1.on.home.com","dahve"); //Mail server, mail server username
    $mail->setText("This is a Subject","This is the body, hi!"); //Subject text, The body of the text
    $mail->setFrom("meyowith@home.com","somebodynot@home.com"); //To:, From:

    $mail->sendMail(); //Send the mail..

    */
    //I think its easyer to have a final "sendMail" command, and have the rest broken up
    //into other parts. but thats just me

    ?>
    [/code]


    [This message has been edited by moderator (edited October 19, 2000).]
  2. #2
  3. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    Well, with that script, I'm not sure..

    when using the mail() function, you simple place that in your "added header"..
    Content-type: text/html

    Frankly, though.. not all mail clients support that.. and to be honest, as much of a web person as I am, I hate email that uses html in it..

    too many malicious users make use of such things..

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    2
    Rep Power
    0
    That script seems to ring a bell, maybe I have seen it before, or something like it? I duno, anyways..... It appears the script doesn't make any function to map a variable/array to the x-headers. Simple as that.

    I agree that the mail() function does take a long time to process. I have not seen a good mail script that uses smtp fully. If I were you, I'd look at the source code for php4, and see what they do inside the mail() function.

    Hope that helps?

    --Jon
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    10
    Rep Power
    0
    thanks,


    I tried looking in the PHP4 source for the mail() function but I couldn't find it Do you know where it is ?


    The built in mail(); function took over 45secs, and this was on an internal Ethernet network. The server itself is a dual pentium pro 200 /w 96mg RAM. I really don't see why it took so damn long. The function up above is relativly instantanious.

Similar Threads

  1. Uploading Files
    By vivekjain in forum ASP Programming
    Replies: 0
    Last Post: February 16th, 2004, 11:21 PM
  2. Help with script
    By akastarlight in forum Perl Programming
    Replies: 1
    Last Post: February 6th, 2004, 06:55 AM
  3. mail() function dropping characters
    By Webbywarehouse in forum PHP Development
    Replies: 2
    Last Post: January 28th, 2004, 01:42 PM
  4. mail function smtp problem
    By emzyme in forum PHP Development
    Replies: 3
    Last Post: January 25th, 2004, 06:59 PM
  5. Help with the mail() function
    By n000b in forum PHP Development
    Replies: 2
    Last Post: January 24th, 2004, 08:14 AM

IMN logo majestic logo threadwatch logo seochat tools logo