Zikula: A Flexible Open Source Content Management System
home | forum | contact us

Dizkus

Bottom
SOLVED: How to use smtp server in Postnuke on registration
  • Posted: 06.08.2004, 16:28
     
    OverMind
    rank:
    Freshman Freshman
    registered:
     July 2004
    Status:
    offline
    last visit:
    06.08.04
    Posts:
    8
    SOLUTION:How to use smtp server instead of PHP's Mail function in 3 steps ;)

    1 - Open the pnAPI.php located in the /includes folder

    2 - Insert a new function there called pnSocketMail() with the following code (change the bold parts to your settings)

    /**
    * send an email via SMTP-server with authentication
    * to be called from pnMail() instead of @mail()
    * @param to - recipient of the email
    * @param subj - title of the email
    * @param body - body of the email
    * @param head - extra headers for the email
    * @param from - user-name on smtp-server
    * @param auth - 1, if authentication required
    * @returns bool
    * @return true if the email was sent, false if not
    */
    //This is the sock mail function for SMTP-Servers with authentication
    // Set the username according to your account
    function pnSockMail( $to, $subj, $body, $head, $from="Username@gmx.de", $auth=1 ) {

    // set these variables according to your needs
    $smtp_acc ="Username@gmx.de"; //account (e.g. Username@gmx.de)
    $smtp_pass="password"; //password
    $smtp_host="mail.gmx.de"; //server SMTP (e.g. mail.gmx.de)


    // the following needs no change
    $lb="\r\n"; //linebreak
    $body_lb="\r\n"; //body linebreak
    $loc_host = "localhost"; //localhost
    $hdr = explode($lb,$head); //header

    if($body) {$bdy = preg_replace("/^\./","..",explode($body_lb,$body));}

    // build the array for the SMTP dialog. Line content is array(command, success code, additonal error message)
    if($auth == 1){// SMTP authentication methode AUTH LOGIN, use extended HELO "EHLO"
    $smtp = array(
    // call the server and tell the name of your local host
    array("EHLO ".$loc_host.$lb,"220,250","HELO error: "),
    // request to auth
    array("AUTH LOGIN".$lb,"334","AUTH error:"),
    // username
    array(base64_encode($smtp_acc).$lb,"334","AUTHENTIFICATION error : "),
    // password
    array(base64_encode($smtp_pass).$lb,"235","AUTHENTIFICATION error : "));
    }
    else {// no authentication, use standard HELO
    $smtp = array(
    // call the server and tell the name of your local host
    array("HELO ".$loc_host.$lb,"220,250","HELO error: "));
    }


    // envelop
    $smtp[] = array("MAIL FROM: <".$from.">".$lb,"250","MAIL FROM error: ");
    $smtp[] = array("RCPT TO: <".$to.">".$lb,"250","RCPT TO error: ");
    // begin data
    $smtp[] = array("DATA".$lb,"354","DATA error: ");
    // header
    $smtp[] = array("Subject: ".$subj.$lb,"","");
    $smtp[] = array("To: ".$to.$lb,"","");
    foreach($hdr as $h) {$smtp[] = array($h.$lb,"","");}
    // end header, begin the body
    $smtp[] = array($lb,"","");
    if($bdy) {foreach($bdy as $b) {$smtp[] = array($b.$body_lb,"","");}}
    // end of message
    $smtp[] = array(".".$lb,"250","DATA(end)error: ");
    $smtp[] = array("QUIT".$lb,"221","QUIT error: ");

    // open socket
    $fp = @fsockopen($smtp_host, 25);
    if (!$fp) echo "Error: Cannot conect to ".$smtp_host."";

    $banner = @fgets($fp, 1024);
    // perform the SMTP dialog with all lines of the list
    foreach($smtp as $req){
    $r = $req[0];
    // send request
    @fputs($fp, $req[0]);
    // get available server messages and stop on errors
    if($req[1]){
    while($result = @fgets($fp, 1024)){if(substr($result,3,1) == " ") { break; }};
    if (!strstr($req[1],substr($result,0,3))) echo"$req[2].$result";
    }
    }
    $result = @fgets($fp, 1024);
    // close socket
    @fclose($fp);
    return 1;
    }



    3 - Make a change in the already existing pnMail() function (search for the function in the file) and change the last lines like in the bold part:


    function pnMail($to, $subject, $message, $headers, $debug=0)
    {
    // Language translations
    switch(pnUserGetLang()) {
    case 'rus':
    if (!empty($headers)) $headers .= "\n";
    $headers .= "Content-Type: text/plain; charset=koi8-r";
    $subject = convert_cyr_string($subject,"w","k");
    $message = convert_cyr_string($message,"w","k");
    $headers = convert_cyr_string($headers,"w","k");
    break;
    }

    // Debug
    if ($debug) {
    echo "Mail To: ".$to."
    ";
    echo "Mail Subject: ".$subject."
    ";
    echo "Mail Message: ".$message."
    ";
    echo "Mail Headers: ".$headers."
    ";
    }

    // Mail message
    // do not display error messages [class007]
    // $return = @mail($to, $subject, $message, $headers); // you can delete this line now if you never intend to use PHP mail function again
    $return = pnSockMail( $to, $subject, $message, $headers );

    return $return;

    }

    Solution originally written here: http://www.post-nuke.net/Article462.htm
  • Posted: 17.08.2004, 12:24
     
    wbassett
    rank:
    Freshman Freshman
    registered:
     August 2004
    Status:
    offline
    last visit:
    22.08.04
    Posts:
    5
    I'm having trouble getting this to work. I get the following error:

    AUTH error:.503 auth not available (#5.3.3) AUTHENTIFICATION error : .502 unimplemented (#5.5.1) AUTHENTIFICATION error : .502 unimplemented (#5.5.1) DATA(end)error: .451 See http://pobox.com/~djb/docs/smtplf.html. QUIT error: .

    I have double checked my mail account information. This is most likely a simple fix...
  • Posted: 25.08.2004, 02:39
     
    php4u
    rank:
    Freshman Freshman
    registered:
     December 1969
    Status:
    offline
    last visit:
    21.04.07
    Posts:
    20
    wbassett, were you able to get this script working? I have PN with Apache on Windows 2000, and need a mail solution.

    thanks!
    Ralph
  • Posted: 01.09.2004, 19:32
     
    rixride
    rank:
    Professional Professional
    registered:
     December 1969
    Status:
    offline
    last visit:
    30.04.08
    Posts:
    796
    I am using Postcast server but trying to find a way to integrate it. Will this solution work?

    --
    -=Rixride=-
    PbxInfo.com
    Postnuke Directory
    PbxJobs.com
    http://www.allrowlett.com
  • Posted: 01.09.2004, 19:39
     
    rank:
    Moderator Moderator
    registered:
     March 2002
    Status:
    offline
    last visit:
    26.08.08
    Posts:
    7720
    The simple recommendation is PostNuke .750 and the mailer module that allows you to specify an external smtp server and account to route any mail from your site through. This supports the standard PHP mail funcition, smtp servers, qmail and sendmail.

    -Mark

Extensions Moderation

Main Menu

Extensions Database

Documentation

Development

Login

Donate to Zikula