Wrox Programmer Forums
|
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 3rd, 2003, 04:26 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default Form help

I want to send contents of an online form to an email address without using the "mailto" command. Is there a way to do it without the user knowing what's going on. After it's sent I want to show thank you page or message. I have the form all ready but I am not sure what I should do next. Can you guys help, or maybe someone out there has a cgi script I could use. Thanks in advance.

Jamie

__________________
-----------------------------------------------------------
\"Don\'t follow someone who\'s not going anywhere\" John Mason
 
Old November 3rd, 2003, 06:30 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Well you would certainly need a server-side script.

Here is a PHP script that would do it:

include three hidden fields in your html form:
<input type='hidden' name='email' value='[email protected]' />
<input type='hidden' name='redirect' value='http://page.togoto.com' />
<input type='hidden' name='subject' value='This message subject'>

These fields may also be left off and specified in the PHP program itself.

Code:
<?php

# auto-mailer.php

# If the email is not specified, set it here
# Will default to [email protected]
#
# To set it to something else do this:
# $_POST["email"] = "[email protected]";

if (!isset($_POST["email"]))

    $_POST["email"] = "webmaster@".$_SERVER["SERVER_NAME"];

# If the subject is not specified, set it here

if (!isset($_POST["subject"]))

    $_POST["subject"] = "Your form results.";

# If the redirect to page is not specified, set it here
# page will redirect to the root www directory for the domain
if (!isset($_POST["redirect"]))

    $_POST["redirect"] = "http://".$_SERVER["HTTP_HOST"];

$mail_body = (string) "The following was submitted on ".gmdate("M d Y H:i:s")."\n\n";

# Dump all fields into the message body
if (isset($_POST) && !empty($_POST))
{
    foreach($_POST as $key => $value)
    {
        if ($key != "email" && $key != "subject" && $key != "redirect")
            $mail_body .= $key.": ".stripslashes($value)."\n\n";
    }
}    

else 
{
    $mail_body .= "There was no data submitted!";
}    

# Send the message
if (!mail($_POST["email"], $_POST["subject"], $mail_body, "From: {$_POST["email"]}"))
{
    echo "Mailer failed! Please check your server's mail settings.";
}

else 
{
    # redirect to the specified location
    header("Location: {$_POST["redirect"]}");
}    

?>
Save this file with a PHP extension. Like mailer.php, or whatever you want and then specify the action attribute of the form tag to reference the same file and the method attribute to 'post':

<form method='post' action='mailer.php'>
...

All of this, of course, requires that you have a PHP-enabled web server.

: )
Rich



:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old November 4th, 2003, 07:45 AM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot for your help. It looks great but my webserver dosen't support PHP. IS there something else that could be recomended.

 
Old November 20th, 2003, 05:26 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You could create an ASP form page with all the field in your form. Then grab those values from this ASP page using either the (POST or GET) method. After that, put those values in your EMAIL.INC file.

What this does is when you submit your ASP page, your browser will automatically email without the user knowing that it did that.

Here are the codes for EMAIL.INC. Do an "include" like this:
 at the end of your ASP codes.

Put both your ASP file and INC file in the same directory. If you understand ASP, great! If not, you'll have to do a little bit of research. Good Luck!!!

<%
Dim strto, strsubject, strbody
dim objCDOMail
strto = session("sessionto")
strfrom=session("sessionuser")
strsubject = "Sample E-mail"
strbody= "Here you can put the values from your form"
strbody= strbody & "More values here(hint, you can create variable(s) to handle the values"

If strto = " " Or Not IsValidEmail(strTo) Then
Else
Set objCDOMail = server.CreateObject("CDONTS.NewMail")
ObjCDOMail.From = strfrom
ObjCDOMail.To = strto
ObjCDOMail.Subject = strSubject
ObjCDOMail.Body = strBody
objCDOMail.send
Set objCDOMail = Nothing
End If
%>






Similar Threads
Thread Thread Starter Forum Replies Last Post
how to set a form as startup form in vb.net 2.0 mallikalapati .NET Framework 2.0 1 February 21st, 2008 09:19 AM
Close all MdiChield form from open one form/Button salman .NET Framework 2.0 6 December 10th, 2007 03:21 AM
Firefox Error when Form Floated / Form locks socoolbrewster CSS Cascading Style Sheets 5 October 6th, 2007 09:59 PM
How to refresh owner form on closing of child form akumarp2p C# 2005 0 December 22nd, 2006 10:27 AM
parent form from child form - urgent plz netfresher C# 1 November 8th, 2006 06:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.