0

I have a contact form on my site when I click send I get the following errors: can anyone help please.

Warning: fsockopen() [function.fsockopen]: unable to connect to 127.0.0.1:25 (Connection refused) in /home/jholmes6/public_html/contact/contactpage/sendmail.php on line 102

Warning: fgets(): supplied argument is not a valid stream resource in /home/jholmes6/public_html/contact/contactpage/sendmail.php on line 103

Warning: Cannot modify header information - headers already sent by (output started at /home/jholmes6/public_html/contact/contactpage/sendmail.php:102) in /home/jholmes6/public_html/contact/contactpage/sendmail.php on line 72

the code to send the email is below:

<

?php

//set variable error var

$er = 0;

//enter the website the contact form is on
$website =  'GetSophos.co.uk';

//Set all POST variables

$name = $_POST['name'];
$email = $_POST['email'];
$message1 = $_POST['message'];
$display = $message1;
$nameto = "Customer Service";  
$from = $email;  
$namefrom = "GetSophos.co.uk";

//check name
    if(!ereg("^[A-Za-z'.-]", $name)) {
        $er = 1;
    }
//check email
    if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$email)) {
        $er = 1;
    }
//check message
    if(!ereg("^[a-zA-Z0-9-]", $message1)) {
        $er = 1;
    }
if ($er == 1)    {
    header("Location: contacterror.php");
}

if ($er == 0)    {    

    // strip slashes if magic quotes on (default).
    if (get_magic_quotes_gpc()) {
            $message1 = stripslashes( $message1 );
        }

    //wordwrap
    $message1 =wordwrap($message1, 70);

    // enter the mail address the form is sent to
    $to  = 'sophos@jcomputingconsultants.co.uk';


    // subject
    $subject = "$website Online Query";

    // message
    $message = "
    <html>
    <head>
      <title>$website Online Query</title>
    </head>
    <body>
      <p><b>Message from:</b> $name</p>
      <p><b>E-mail Address:</b> $email</p>
      <p><b>Message:</b> $display</p>


    </body>
    </html>
    ";


authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);  

header("Location:contactsuccess.php");

}

/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */

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




    /* * * * * * * * * * * * * * 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 = "web@jccemail.co.uk";
    $password = "Holmesdirectory1";
    $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";
    }



    //Say Hello to SMTP
    fputs($smtpConnect, "EHLO $localhost" . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['heloresponse'] = "$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);
    fputs($smtpConnect, base64_encode($password) . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['authpassword'] = "$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:" . $newLine;
    $headers .= "From:$email" . $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";

    //print "<PRE>";
    //var_dump($logArray); 
}

?>
3
Contributors
2
Replies
12
Views
4 Years
Discussion Span
Last Post by jalpesh_007
9

@jcomputing

Warning: Cannot modify header information - headers already sent by (output started at /home/jholmes6/public_html/contact/contactpage/sendmail.php:102) in /home/jholmes6/public_html/contact/contactpage/sendmail.php on line 72

What is this for:

header("Location:contactsuccess.php");

Another words, I don't think you need this unless you want to redirect to that page?

Warning: fsockopen() [function.fsockopen]: unable to connect to 127.0.0.1:25 (Connection refused) in /home/jholmes6/public_html/contact/contactpage/sendmail.php on line 102

Warning: fgets(): supplied argument is not a valid stream resource in /home/jholmes6/public_html/contact/contactpage/sendmail.php on line 103

Regarding about this:

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

It means you have a connect issue. You need to fixed that connection in order to work correctly.

0

$smtpServer = "127.0.0.1";"

Instead of this try to write the host name.like //smtp.google.com or anything else..
then call the function.

Edited by jalpesh_007

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.