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);
}
?>