Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Thanked 0 Times in 0 Posts

    php SMTP authgMail() function & Return-Path Problem

    I want to add return path to this function but I have no idea what to do.

    With this script I can send email but if email bounced it should return to specified Return_email_address.

    There for I want to know where I can add this Return_email_address in this function.
    I added to :
    $headers .= "Return-path: me<$$return >" . $newLine;
    but it is not working.


    function authgMail($from, $namefrom, $to, $nameto, $subject, $message)

    $smtpServer = "mail.quantumkw.com"; //does not accept STARTTLS

    $port = "25"; // try 587 if this fails

    $timeout = "45"; //typical timeout. try 45 for slow servers

    $username = "sa"; //your gmail account

    $password = "sa123"; //the pass for your gmail

    $localhost = $_SERVER['REMOTE_ADDR']; //requires a real ip

    $newLine = "\r\n"; //var just for newlines

    /* you shouldn't need to mod anything else */

    //connect to the host and port

    $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);

    //echo $errstr." - ".$errno;

    $smtpResponse = fgets($smtpConnect, 4096);



    $output = "Failed to connect: $smtpResponse";

    //echo $output;

    return $output;




    $logArray['connection'] = "Connected to: $smtpResponse";

    //echo "connection accepted<br>".$smtpResponse."<p />Continuing<p />";

    //echo $tadr;


    //you have to say HELO again after TLS is started

    fputs($smtpConnect, "HELO $localhost". $newLine);

    $smtpResponse = fgets($smtpConnect, 4096);

    $logArray['heloresponse2'] = "$smtpResponse";

    //request for auth login

    fputs($smtpConnect,"AUTH LOGIN" . $newLine);

    $smtpResponse = fgets($smtpConnect, 4096);

    $logArray['authrequest'] = "$smtpResponse";

    //send the username

    fputs($smtpConnect, base64_encode($username) . $newLine);

    $smtpResponse = fgets($smtpConnect, 4096);

    $logArray['authusername'] = "$smtpResponse";

    //send the password

    fputs($smtpConnect, base64_encode($password) . $newLine);

    $smtpResponse = fgets($smtpConnect, 4096);

    $logArray['authpassword'] = "$smtpResponse";

    //email from

    fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);

    $smtpResponse = fgets($smtpConnect, 4096);

    $logArray['mailfromresponse'] = "$smtpResponse";

    //email to

    fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);

    $smtpResponse = fgets($smtpConnect, 4096);

    $logArray['mailtoresponse'] = "$smtpResponse";

    //the email

    fputs($smtpConnect, "DATA" . $newLine);

    $smtpResponse = fgets($smtpConnect, 4096);

    $logArray['data1response'] = "$smtpResponse";

    //construct headers

    $headers = "MIME-Version: 1.0" . $newLine;

    $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;

    $headers .= "From: $namefrom <$from>" . $newLine;

    //observe the . after the newline, it signals the end of message

    fputs($smtpConnect, "To: <$to>\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");

    $smtpResponse = fgets($smtpConnect, 4096);

    $logArray['data2response'] = "$smtpResponse";

    // say goodbye

    fputs($smtpConnect,"QUIT" . $newLine);

    $smtpResponse = fgets($smtpConnect, 4096);

    $logArray['quitresponse'] = "$smtpResponse";

    $logArray['quitcode'] = substr($smtpResponse,0,3);


    //a return value of 221 in $retVal["quitcode"] is a success

    $a='Mail Sent Sucessfully';



    echo $a;


    this sending script using authgMail() function
    //// With SMTP Server
    $usertext="<br><br>Sender Email<font color=#333333>: " . $email ."</font>";
    $usertext.= "<br><br><font face=verdana size=2 color=#000000><b>This message was sent from:</b><br> " .$http_referrer;
    $usertext.= "<br><br><font face=verdana size=2 color=#000000><b>This message was sent from User IP:</b><br> " .$http_ip;
    $usertext.= "<br><hr>Message:<hr><br>";
    $messageend= "<br><hr>";

    $to = $yourEmail;
    $nameto = "To The Manager";
    $from = cleanPosUrl($_REQUEST['posName'])." <".cleanPosUrl($_REQUEST['posEmail']);
    $namefrom = cleanPosUrl($_REQUEST['posName']);
    $nameto = "reciever;
    $subject = cleanPosUrl($_REQUEST['posRegard']);
    $message = $usertext.$messageend;

    // this is it, lets send that email!
    //echo $message;

    // exit;
    $result=authgMail($from, $namefrom, $to, $nameto, $subject, $message);

    if ( $result==true )
    {$posConfirmation = '<font color=green size=-1><strong>Success! Your Email has been sent. Hope you enjoyed your stay.</strong></font>'; }
    {$posConfirmation = 'Your Email could not be sent. Please try back at another time.SMTP'; }

    Guys Plz if you know what to do and where must I change code then please suggest me

  2. #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Toronto, Ontario
    Thanked 122 Times in 122 Posts
    from the php manual:

    A quick note about the optional flags that can be passed to sendmail. -f will set the From address, -r will override the default Return-path that sendmail generates (typically the From address gets used). If you want your bouncebacks to go to a different address than the from address, try using both flags at once: "-f myfromemail@example.com -r mybounceemail@example.com"


Posting Permissions

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