Jump to content

PHP Mailing Blues


chain2005

Recommended Posts

I'm building an autoresponder service similiar to 1ShoppingCart.com and frankly I'm having the PHP Mailing Blues... It should be so much easier! I can get everything to mail out fine the problem is a lot of spam blockers are blocking my emails. I started off using the mail() but new it's limitations soon moved to a pre-coded SMTP mailer (see code below)... Now everytime an email is sent out to like a Hotmail account it always goes directly into the Junk Mail container. Hotmail is saying all these emails do not have a SENDER ID. I'm not sure what that is or how to set one, which is pretty much why I've come here! If anyone knows how I could fix this, I would owe my deepest gratitude to! This problem has been costing me a lot of time! Just a reminder everything works properly when sent to a local email but outside emails are not working...

 

function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)
{
    //SMTP + SERVER DETAILS
    /* * * * CONFIGURATION START * * * */
    $smtpServer = "localhost";
    $port = "25";
    $timeout = "30";
    $username = "";
    $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";    
} 

Link to comment
https://forums.phpfreaks.com/topic/45370-php-mailing-blues/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.