email send using localhost

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Noorain
    New Member
    • Mar 2008
    • 57

    email send using localhost

    i worked in xampp.

    i want to email through localhost in web mail. For this i changed SMTP from php.ini file. i used web mail ip in SMTP.

    i used following code:

    Code:
    <?php
    function authSendEmail($from, $namefrom, $to, $subject, $message)
    {
    //SMTP + SERVER DETAILS
    /* * * * CONFIGURATION START * * * */
    $smtpServer = "10.172.0.90";
    $port = "25";
    $localhost = "localhost";
    $newLine = "\r\n";
    /* * * * CONFIGURATION END * * * * */
    
    //Connect to the host on the specified port
    $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr);
    $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";
    
    //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
    $header = "MIME-Version: 1.0" . $newLine;
    $header .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
    $header .= "From: $namefrom <$from>" . $newLine;
    
    fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$header\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";
    }
    ?>
    
    <? include('common/header1.inc');?>
    <?php
     
    // Change these two variables to meet your needs.
     
    //$myemail = 'web@onebankbd.com';
    $myemail = 'noorain.it.chq@onebankbd.com';
    //$myemail = 'noorain_ak@yahoo.com';
    /*gmail and yahoo tested, donno abt hotmail and other.*/
    $subject = 'OBL FEEDBACK FORM';
    //echo $myemail;
     
    $op = $_POST[op];
     
    if($op == 'contact')
    {
        $c_name = stripslashes($_POST[txtname]);
    	$c_address = stripslashes($_POST[txtaddress]);
    	$c_phone = stripslashes($_POST[txtphone]);
        $c_email = stripslashes($_POST[txtmail]);
    	$c_text = stripslashes($_POST[txtmsg]);
        //$referer = $_POST[referer];
        //$remote_host = $_SERVER[REMOTE_ADDR];
        //$server = $_SERVER[SERVER_NAME];
        //$browser = $_SERVER[HTTP_USER_AGENT];
     
        if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$",$c_email)) 
        { 
            $status = "We're sorry, but you've entered an incorrect email address.<br>";
        }
        
    	if(!$c_name)
        {
            $status .= "Please enter your name.<br>";
        }
        if(!$c_text)
        {
            $status .= "Please enter a message.<br>";
        }
    	if(!$c_address)
        {
            $status .= "Please enter your address.<br>";
        }
     
        if(!$status)
        {
            $message = "Name: $c_name<br>
    					Address: $c_address<br>
    					Phone: $c_phone<br>
    					Email: $c_email<br>
    					Subject: $subject<br><br>
    					$c_text";
    		
    		authSendEmail($c_email, $c_name, $myemail, $subject, $message);
    		$status = "Thank you for your Feedback!!<br><br>";
        }
        else
        {
            $status .= "<br>";
        }
    }    
     
    // Now check the referer page and ensure it's a proper URL
     
    $referer = $_SERVER[HTTP_REFERER];
     
    if(!preg_match('#^http://[a-z0-9-]+.([a-z0-9-]+.)?[a-z]+#i', $referer))
    {
        unset($referer);
    }
     
    ?>
     
    
    <!-- Begin Body Tag -->
    <table width="100%" cellspacing="0" cellpadding="0">
            <tr>
              <td><img src="_img/spacer.gif" width="1" height="6" /></td>
            </tr>
          </table>
          <table width="100%" cellspacing="0" cellpadding="0">
            <tr>
              <td width="214"><table width="100%" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="8"><img src="_img/corner-l.gif" width="13" height="10" /></td>
                  <td background="_img/corner-bg.gif"><img src="_img/spacer.gif" width="1" height="10" /></td>
                  <td width="8"><img src="_img/corner-r.gif" width="12" height="10" /></td>
                </tr>
              </table></td>
              <td width="4"><img src="_img/spacer.gif" width="6" height="1" /></td>
              <td><table width="100%" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="8"><img src="_img/corner-l.gif" width="13" height="10" /></td>
                  <td background="_img/corner-bg.gif"><img src="_img/spacer.gif" width="1" height="10" /></td>
                  <td width="8"><img src="_img/corner-r.gif" width="12" height="10" /></td>
                </tr>
              </table></td>
            </tr>
          </table>
          <table width="100%" cellspacing="0" cellpadding="0">
            <tr>
              <td width="214" valign="top" bgcolor="#FFFFFF">
    <!-- BEGIN JAVASCRIPT FOR POPUP-->
    <script type="text/javascript">
    <!--
    function popup(url) 
    {
     var width  = 768;
     var height = 485;
     var left   = (screen.width  - width)/2;
     var top    = (screen.height - height)/2;
     var params = 'width='+width+', height='+height;
     params += ', top='+top+', left='+left;
     params += ', directories=no';
     params += ', location=no';
     params += ', menubar=no';
     params += ', resizable=no';
     params += ', scrollbars=yes';
     params += ', status=no';
     params += ', toolbar=no';
     newwin=window.open(url,'windowname5', params);
     if (window.focus) {newwin.focus()}
     return false;
    }
    // -->
    </script>
    <!-- END JAVASCRIPT FOR POPUP-->
    <table width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td><? include('common/products-services.php');?></td>
      </tr>
    </table>
    <table width="100%" cellspacing="0" cellpadding="0">
                <tr>
                  <td><? include('common/info-obl.php');?></td>
                </tr>
              </table></td>
              <td width="4"><img src="_img/spacer.gif" width="6" height="1" /></td>
              <td valign="top" bgcolor="#FFFFFF"><table width="100%" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="10"><img src="_img/spacer.gif" width="18" height="1" /></td>
                  <td>
    			  <table width="100%" cellspacing="0" cellpadding="0">
                    <tr>
                      <td><img src="_img/spacer.gif" width="1" height="6" /></td>
                    </tr>
                    <tr>
                      <td height="25" valign="top" class="headertxt">Feedback</td>
                    </tr>
                    <tr>
                      <td bgcolor="#F0F0F0"><img src="_img/spacer.gif" width="1" height="1" /></td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td>Please let us know if you require more 
                          information, or if you have any comments. </td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td align="center" style="color:#FE0000; font-size:12px;"><?php print $status; ?></td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td align="center"><table width="75%" cellpadding="1" cellspacing="0" bgcolor="#CCCCCC">
                        <tr>
                          <td><table width="100%" cellpadding="6" cellspacing="0" bgcolor="#F0F0F0">
                              <tr>
                                <td><table width="100%" cellspacing="0" cellpadding="0">
                                    <tr>
                                      <td>&nbsp;</td>
                                    </tr>
                                    <tr>
                                      <td><table width="100%" cellspacing="0" cellpadding="0">
                                          <tr>
                                            <td width="15"><img src="_img/spacer.gif" width="15" height="1" /></td>
                                            <td align="center"><table cellspacing="0" cellpadding="3">
                                                <form method="post" action="<?php print $_SELF; ?>">
    											<tr>
                                                  <td width="50" align="right"><span class="style4">Name :</span></td>
                                                  <td align="left"><input name="txtname" type="text" id="txtname" style="font-size:10px;" size="50"/>
                                                    <span style="color: #FE0000">*</span></td>
                                                </tr>
                                                <tr>
                                                  <td align="right" valign="top"><span class="style4">Address : </span></td>
                                                  <td align="left"><textarea name="txtaddress" cols="36" rows="3" id="txtaddress" style="font-size:12px;"></textarea>
                                                    <span style="color: #FE0000">*</span></td>
                                                </tr>
                                                <tr>
                                                  <td align="right"><span class="style4"> Phone : </span></td>
                                                  <td align="left"><input name="txtphone" type="text" id="txtphone" style="font-size:10px;" size="50" /></td>
                                                </tr>
                                                <tr>
                                                  <td align="right"><span class="style4">E-mail : </span></td>
                                                  <td align="left"><input name="txtmail" type="text" id="txtmail" style="font-size:10px;" size="50" />
                                                    <span style="color: #FE0000">*</span></td>
                                                </tr>
                                                <tr>
                                                  <td align="right" valign="top"><span class="style4">Message : </span></td>
                                                  <td align="left" valign="top"><textarea name="txtmsg" cols="36" rows="6" id="txtmsg" style="font-size:12px;"></textarea>
                                                    <sub><span style="color: #FE0000">*</span></sub></td>
                                                </tr>
                                                <tr>
                                                  <td valign="top">&nbsp;</td>
                                                  <td align="left"><input type="submit" name="Submit" value="Submit" style="font-size:10px;" />
                                                    <input type="hidden" name="op" value="contact" />
                                                    <input type="hidden" name="referer" value="<?php print $referer; ?>" /></td>
                                                </tr></form>
                                            </table></td>
                                            <td width="15"><img src="_img/spacer.gif" width="15" height="1" /></td>
                                          </tr>
                                      </table></td>
                                    </tr>
                                    <tr>
                                      <td>&nbsp;</td>
                                    </tr>
                                </table></td>
                              </tr>
                          </table></td>
                        </tr>
                      </table></td>
                    </tr>
                    <tr>
                      <td align="center">&nbsp;</td>
                    </tr>
                  </table>			  </td>
                  <td width="10"><img src="_img/spacer.gif" width="18" height="1" /></td>
                </tr>
              </table></td>
            </tr>
          </table>
    <!-- End Body Tag -->
    <DIV id=overDiv style="Z-INDEX: 1; POSITION: absolute"></DIV>
    <SCRIPT language=JavaScript src="js/br/overlib.js"></SCRIPT>
    <? include('common/footer.inc');?>
    but following message show:

    Warning: fsockopen() [function.fsocko pen]: unable to connect to 10.172.0.90:25 (No connection could be made because the target machine actively refused it. ) in D:\Program Fiels\xampp\htd ocs\OBL-CPANEL1\test-mail07.php on line 14

    Warning: fgets() expects parameter 1 to be resource, boolean given in D:\Program Fiels\xampp\htd ocs\OBL-CPANEL1\test-mail07.php on line 15


    Do u please why this problem arise.

    Thanks
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    It's quite obvious why this is happening. The socket you're trying to connect is refusing your attempt, ergo, you never get a socket resource.

    Comment

    Working...