Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP web email form not directing to Error/Thank You pages
Old 09-15-2009, 11:16 AM PHP web email form not directing to Error/Thank You pages
Average Talker

Posts: 28
Name: Rhowena MacCuish
Trades: 0
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 ...]

}
?>
rhowbust is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-15-2009, 04:49 PM Re: PHP web email form not directing to Error/Thank You pages
orionoreo's Avatar
Ultra Talker

Posts: 335
Name: Jerry
Trades: 0
first of all your code doesn't load properly

there's a couple errors making it not run... It doesn't run anything for me but I got redirected to an error page:

PHP Code:
<?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($smtpConnect515);
    
    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($smtpConnect515);
    
$logArray['heloresponse'] = "$smtpResponse";
    
    
//Email From
    
fputs($smtpConnect"MAIL FROM: $from$newLine);
    
$smtpResponse fgets($smtpConnect515);
    
$logArray['mailfromresponse'] = "$smtpResponse";
    
    
//Email To
    
fputs($smtpConnect"RCPT TO: $to$newLine);
    
$smtpResponse fgets($smtpConnect515);
    
$logArray['mailtoresponse'] = "$smtpResponse";
    
    
//The Email
    
fputs($smtpConnect"DATA" $newLine);
    
$smtpResponse fgets($smtpConnect515);
    
$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($smtpConnect515);
    
$logArray['data2response'] = "$smtpResponse";
    
    
// Say Bye to SMTP
    
fputs($smtpConnect,"QUIT" $newLine);
    
$smtpResponse fgets($smtpConnect515);
    
$logArray['quitresponse'] = "$smtpResponse";
}


$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';

if (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 ...]

}
?>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
orionoreo is offline
Reply With Quote
View Public Profile
 
Old 09-16-2009, 01:50 AM Re: PHP web email form not directing to Error/Thank You pages
bmcoll3278's Avatar
Super Talker

Posts: 118
Name: Brian Collins
Trades: 0
If it works on your server great I dont have the use of smtp

But just an idea. look at this line
$ctf_redirect_url = 'index.html';

if the php file is in a diff dir. you may need to make this line
$ctf_redirect_url = '../index.html';
or even use the full url
$ctf_redirect_url = 'http://www.yoursite.com/index.html';

That may be the problem if the mail file is not in the same folder as index.html.
__________________
I hope to build a site with something for every one

Please login or register to view this content. Registration is FREE

Last edited by bmcoll3278; 09-16-2009 at 01:53 AM..
bmcoll3278 is offline
Reply With Quote
View Public Profile Visit bmcoll3278's homepage!
 
Old 09-17-2009, 11:33 AM Re: PHP web email form not directing to Error/Thank You pages
Average Talker

Posts: 28
Name: Rhowena MacCuish
Trades: 0
I was told this was the correct code to make the connection to the server to send messages from the web form but that is not working either. When I try testing I still get the blank PHP page which should at least have the error message
"Error
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." It's there when I test it in DW but not when it goes live??

orionoreo - you said you got an error page, but it wasn't running anything are you able to highlight what is stopping it from running?

I have adjusted the Thankyou and Redirect to URLs as suggested by bmcoll3278, maybe this will work when the code finaly does what it is ment to.

Thanks for your input guys! This surely should be a simple thing to do but it's driving me mad!
rhowbust is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP web email form not directing to Error/Thank You pages
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15372 seconds with 12 queries