Results 1 to 3 of 3
  1. #1

    Default Autheticating PHP mail

    Just heard that we need to authenticate PHP emails from web forms. I tried to follow the script that was suggested in my email from EUK by putting in my own details but it just times out....has anyone got this working...here's the script, I fall down on line 87, timeout because it can't connect to the server.

    $smtpResponse = fgets($smtpConnect, 515);

    Code:
    <?php  
    //new function  
     
    $to = "To Email Address";  
    $nameto = "Your Name";  
    $from = "test@yourdomain.com";  
    $namefrom = "Who From";  
    $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 = "127.0.0.1";
    $port = "25";
    $timeout = "30";
    $username = "test@yourdomain.com";
    $password = "email account password";
    $localhost = "localhost";
    $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";
    }
    ?>

  2. #2
    Join Date
    Apr 2010
    Location
    The KOP END
    Posts
    237

    Default

    Hello

    This is right now only implemented for our shared Linux hosting accounts only. If you still wish to use authentication that is a positive step ahead. But the way to do it is different. Please create a ticket and provide me the link to your script in this ticket along with the ticket number here for further investigation.

    Thanks,
    Ray

  3. #3

    Default

    Thanks, ok, I've opened a ticket. The above script I'm running can be found here:

    http://www.image-room.com/email_test.php

    I guess running PHP from Windows servers is unusual but this could be a problem for a few people.

    Ticket number: #URW-469-49000

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •