|
Hi This codes Lets me send mails via the server my website is hosted on. It does not have send mail so I have to connect this way to use my HTML email webform. The problem is, it does not go to an error page or to the sent thank you page. instead it just shows the blank php page. Have I put the instructions in the wrong place or miss coded. Any help would be greatly appreciated.
Thank you!
<?php
//new function
$to = "info@mywebsite.co.uk";
$nameto = "Enquiries";
$from = $_REQUEST['email'];
$namefrom = $_REQUEST['name'];
$message = $_REQUEST['comments'];
authSendEmail($from, $namefrom, $to, $nameto, $message);
?>
<?php
/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */
//Authenticate Send - 21st March 2005
//This will send an email using auth smtp and output a log array
//logArray - connection,
function authSendEmail($from, $namefrom, $to, $nameto, $message)
{
//SMTP + SERVER DETAILS
/* * * * CONFIGURATION START * * * */
$smtpServer = "mail.mywebsite.co.uk";
$port = "25";
$timeout = "30";
$localhost = "IP ADDRESS HERE";
$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, "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";
}
?>
<?php
$success_page = 'contactsent.html'; //confirmation message page
//If there are NO mistakes in the field, user will redirect to this page
// Redirect to Home Page after message is sent
// SET $ctf_redirect_enable = 1; ON, $ctf_redirect_enable = 0; for OFF.
$ctf_redirect_enable = 1;
// Used for the delay timer once the message has been sent
$ctf_redirect_timeout = 5; // time in seconds to wait before loading another Web page
// Web page to send the user to after the time has expired
$ctf_redirect_url = 'index.html';
elseif (empty($name) || (empty($email) || empty($comments)) {
header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
?>
<html>
<head><title>error</title></head>
<body>
<h1>Error</h1>
<p>
Oops, it appears you forgot to enter either your
name, email address or your comments. Please press the BACK
button in your browser and try again.
</p>
</body>
</html>
<?php
}
if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
[... direct user to an error page and quit ...]
}
?>
|