Hi guys, I have recently tried to integrate the following script into my website to use with contact form (found here - http://www.codewalkers.com/c/a/Email-Code/Smtp-Auth-Email-Script/)

My Script looks like this:

<?php  
    //new function  
    $to = "hicky2k@hotmail.com";
    $nameto = "rhys";
    $from = $_REQUEST['client_email'];
    $namefrom = $_REQUEST['client_name'];
    $subject = "Hello World Again!";
    $message = "World, Hello!";
    authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);
    ?>  


    <?php  
    /* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */   

    //This will send an email using auth smtp and output a log array  
    //logArray - connection,   

    function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)  
    {  
        //SMTP + SERVER DETAILS  
        /* * * * CONFIGURATION START * * * */ 
        $smtpServer = "mail.limedomains.net";
        $port = "25";
        $timeout = "30";
        $username = "*******";
        $password = "*******";
        $localhost = "mail.limedomains.net";
        $newLine = "\r\n";
        /* * * * CONFIGURATION END * * * * */ 

        //Connect to the host on the specified port  
        $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);  
        $smtpResponse = fgets($smtpConnect, 515);  
        if(empty($smtpConnect))   
        {  
            $output = "Failed to connect: $smtpResponse";  
            return $output;  
        }  
        else 
        {  
            $logArray['connection'] = "Connected: $smtpResponse";  
        }  

        //Request Auth Login  
        fputs($smtpConnect,"AUTH LOGIN" . $newLine);  
        $smtpResponse = fgets($smtpConnect, 515);  
        $logArray['authrequest'] = "$smtpResponse";  

        //Send username  
        fputs($smtpConnect, base64_encode($username) . $newLine);  
        $smtpResponse = fgets($smtpConnect, 515);  
        $logArray['authusername'] = "$smtpResponse";  

        //Send password  
        fputs($smtpConnect, base64_encode($password) . $newLine);  
        $smtpResponse = fgets($smtpConnect, 515);  
        $logArray['authpassword'] = "$smtpResponse";  

        //Say Hello to SMTP  
        fputs($smtpConnect, "HELO $localhost" . $newLine);  
        $smtpResponse = fgets($smtpConnect, 515);  
        $logArray['heloresponse'] = "$smtpResponse";  

        //Email From  
        fputs($smtpConnect, "MAIL FROM: $from" . $newLine);  
        $smtpResponse = fgets($smtpConnect, 515);  
        $logArray['mailfromresponse'] = "$smtpResponse";  

        //Email To  
        fputs($smtpConnect, "RCPT TO: $to" . $newLine);  
        $smtpResponse = fgets($smtpConnect, 515);  
        $logArray['mailtoresponse'] = "$smtpResponse";  

        //The Email  
        fputs($smtpConnect, "DATA" . $newLine);  
        $smtpResponse = fgets($smtpConnect, 515);  
        $logArray['data1response'] = "$smtpResponse";  

        //Construct Headers  
        $headers = "MIME-Version: 1.0" . $newLine;  
        $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;  
        $headers .= "To: $nameto <$to>" . $newLine;  
        $headers .= "From: $namefrom <$from>" . $newLine;  

        fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");  
        $smtpResponse = fgets($smtpConnect, 515);  
        $logArray['data2response'] = "$smtpResponse";  

        // Say Bye to SMTP  
        fputs($smtpConnect,"QUIT" . $newLine);   
        $smtpResponse = fgets($smtpConnect, 515);  
        $logArray['quitresponse'] = "$smtpResponse";  
        
        var_dump($logArray); 
    }  
    ?>

Basically it is not working, so I have added the var_dump() function at the bottom, amnd the following message is displayed:

array(10) { ["connection"]=> string(51) "Connected: 220 ********************************** " ["authrequest"]=> string(39) "503 5.5.1 Error: send HELO/EHLO first " ["authusername"]=> string(41) "502 5.5.2 Error: command not recognized " ["authpassword"]=> string(41) "502 5.5.2 Error: command not recognized " ["heloresponse"]=> string(26) "250 mail.limedomains.net " ["mailfromresponse"]=> string(14) "250 2.1.0 Ok " ["mailtoresponse"]=> string(54) "554 5.7.1 : Relay access denied " ["data1response"]=> string(38) "554 5.5.1 Error: no valid recipients " ["data2response"]=> string(41) "502 5.5.2 Error: command not recognized " ["quitresponse"]=> string(41) "502 5.5.2 Error: command not recognized " }

Anybody got any idea what it could mean, and any suggestions how to solve this problem?

Thanks in advance

Rhys

Recommended Answers

All 5 Replies

Looks like the SMTP Server wants the HELO command before you send the USER command.

Is there a reason you want to do this by sending the separate commands manually ? I recommend using a tool like PHPMailer instead.

Well I was looking at using PHPPear or something similiar that would deal with emailing however the hositing site doesn't support these tools.

I'll give it a try swapping the two commands around and see what I'll get.

A package like PHPMailer can be installed/used by just copying a folder to the server. No need to install additional stuff like PEAR does.

hello

just need to install pear package for works short code of php emailer.. pear class will use like


pear install SMTP_NET
pear install pear/mail


SNIP

Member Avatar for letoii

I added the following to the authSendEmail function and got rid of the errors

put it before your Authorization Request (//Request Auth Login)

fputs($smtpConnect,"HELO $smtpServer" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['helorequest'] = "$smtpResponse";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.