Log in

View Full Version : I'm not sure if this is a PHP thing... but for Email



ckydoofy13
09-23-2006, 11:59 PM
Ok... this is what I want to do, I have Dreamweaver to work with if you needed that information. What I want to do is have a website where people fill out information with selecting, Male or Female or fill in there Location stuff like that, which I already know how to do, Im just letting you know all the details... heres the part I dont know what to do!

When I want them to submit it, it gathers all the information (correct information) into and email and has them send it to my email adress, WHICH I DONT WANT!!! Is there a way where when they press submit it automaticly sends it to my email with out the email page. Sorry if any of this sounds confusing! But Please Help!

djr33
09-24-2006, 01:03 AM
You probably have <form action="mailto:your@email.com">, right?

The action is where the form data is sent. Using that, it's the easy way out... just use the person's email program to send it to you. But as you've discovererd, it's annoying, and not too compatible.

So, the solution is to use php to interpret the data then send.

First, in your form tag-- <form method="post" action="nextpage.php">
(You can also use method="get", but that puts the data into the next url, like nextpage.php?variable=value, which is useful, but gets to be a bit much when a lot of data is sent.)

Next, using php, those values are available-
$_POST['fieldname'] is the value of the field sent that had the name "fieldname", like <input name="fieldname">.

Do what you want with it using php (just get a basic idea of what's going on and it's pretty easy.)

I'd suggest visiting php.net for more info.

After you're done, use the mail() function to send it to your email.

Info on that also available at php.net.

ckydoofy13
09-24-2006, 01:39 AM
Now is there a way possible without using php, that doesn't conflicted with the email situation?

djr33
09-24-2006, 02:26 AM
PHP is a particular language. There are other server side programming languages available.

Also, you can specify, as the action, a free form interpreter. Just google "form mailer".
Basically, it will take the data, then send it to you.
However, you won't then have control over the format.. it'll just do it like:
fieldname: data
fieldname: data
etc.
And, the other problem is that it'll usually come with ads.

However, if you don't want to get into the coding side of things, this is a good solution.

blm126
09-24-2006, 03:57 AM
If you look for a form mailer check with you host first. Many provide one for free.

djr33
09-24-2006, 04:27 AM
Yes, that's true, and would be most likely to be customizable and/or free of ads.

ckydoofy13
09-27-2006, 11:54 PM
ok... I did what you said with the form, its method="post" and the action= "nextpage.php" but you kinda lost me after that? when I preview it and click on the button it takes you to the nextpage.php but im not sure why i did that.


"Next, using php, those values are available-
$_POST['fieldname'] is the value of the field sent that had the name "fieldname", like <input name="fieldname">."

I dont under stand, do I creat a page thats called nextpage.php and then....what? sorry im new to php...

blm126
09-28-2006, 01:20 AM
My advice is to find a form mailer.

ckydoofy13
09-28-2006, 02:01 AM
Im a little confused on how that works too? can you try and explain it a little more and what I use and do? my internet provider is comcast and its cable and i sure there isn't a form mailer with it...

blm126
09-28-2006, 02:45 AM
I said your host may provide one. By that I mean the person who runs the server that presents the page to the web.

ckydoofy13
09-28-2006, 02:48 AM
oh i see, Ill check!

ckydoofy13
09-28-2006, 03:01 AM
ok... no they dont give it to me... is another name for it POP mail? thats all they had and it was a forwarding thing but it cost more money to do that... I perfer the free way!

ckydoofy13
09-28-2006, 03:36 AM
Can you look over this and see if this is what I need... also tell me if i need to change anything on it I noticed up top where i need my domain name and email adress...



<?php
/* PHP Form Mailer - phpFormMailer v2.1, last updated 30th Nov 2005 - check back often for updates!
(easy to use and more secure than many cgi form mailers) FREE from:
www.TheDemoSite.co.uk
Should work fine on most Unix/Linux platforms */

// ------- three variables you MUST change below -------------------------------------------------------
$valid_ref1="http://Your--domain/contact.html";// chamge "Your--domain" to your domain
$valid_ref2="http://www.Your--domain/contact.html";// chamge "Your--domain" to your domain
$replyemail="YOU@Your--domain";//change to your email address
// ------------------------------------------------------------

//clean input in case of header injection attempts!
function clean_input_4email($value, $check_all_patterns = true)
{
$patterns[0] = '/content-type:/';
$patterns[1] = '/to:/';
$patterns[2] = '/cc:/';
$patterns[3] = '/bcc:/';
if ($check_all_patterns)
{
$patterns[4] = '/\r/';
$patterns[5] = '/\n/';
$patterns[6] = '/%0a/';
$patterns[7] = '/%0d/';
}
//NOTE: can use str_ireplace as this is case insensitive but only available on PHP version 5.0.
return preg_replace($patterns, "", strtolower($value));
}

$name = clean_input_4email($_POST["name"]);
$email = clean_input_4email($_POST["email"]);
$thesubject = clean_input_4email($_POST["thesubject"]);
$themessage = clean_input_4email($_POST["themessage"], false);

$error_msg='ERROR - not sent. Try again.';

$success_sent_msg='<p align="center"><strong>&nbsp;</strong></p>
<p align="center"><strong>Your message has been successfully sent to us<br>
</strong> and we will reply as soon as possible.</p>
<p align="center">A copy of your query has been sent to you.</p>
<p align="center">Thank you for contacting us.</p>';

$replymessage = "Hi $name

Thank you for your email.

We will endeavour to reply to you shortly.

Please DO NOT reply to this email.

Below is a copy of the message you submitted:
--------------------------------------------------
Subject: $thesubject
Query:
$themessage
--------------------------------------------------

Thank you";

// email variable not set - load $valid_ref1 page
if (!isset($_POST['email']))
{
echo "<script language=\"JavaScript\"><!--\n ";
echo "top.location.href = \"$valid_ref1\"; \n// --></script>";
exit;
}

$ref_page=$_SERVER["HTTP_REFERER"];
$valid_referrer=0;
if($ref_page==$valid_ref1) $valid_referrer=1;
elseif($ref_page==$valid_ref2) $valid_referrer=1;
if(!$valid_referrer)
{
echo "<script language=\"JavaScript\"><!--\n alert(\"$error_msg\");\n";
echo "top.location.href = \"$valid_ref1\"; \n// --></script>";
exit;
}
$themessage = "name: $name \nQuery: $themessage";
mail("$replyemail",
"$thesubject",
"$themessage",
"From: $email\nReply-To: $email");
mail("$email",
"Receipt: $thesubject",
"$replymessage",
"From: $replyemail\nReply-To: $replyemail");
echo $success_sent_msg;
/*
PHP Form Mailer - phpFormMailer (easy to use and more secure than many cgi form mailers)
FREE from:

www.TheDemoSite.co.uk */
?>

djr33
09-28-2006, 05:02 AM
That script isn't too complex, but might be more than you need.
It depends what you want.
It has a nice little security validator to be sure the messages don't contain anything that would cause problems, but not sure if that's needed.

If you want to code it yourself, learn php. There's no shortcut.

$_POST['test'] would hold the value of <input type="*any*" name="test"> once sent to the next page.

For example...

on next page.php, you could have:
<?php mail($_PoST['test']); ?>
and it would mail the contents of the "test" field from the form.

HOWEVER, the mail function needs 4 values:
to (who it's sent to)
subject
body (text, etc.)
and special headers, such as from, reply-to, special encoding, etc.

For example, here's a simple setup--
your form on page1:
<form action="TYPETHENAMEOFYOURNEXTPAGEHERE.php" method="post">
<input type="hidden" value="some@one.com" name="to">
<input type="text" name="subject">
<textarea name="body"></textarea>
<input type="submit">
</form>

Note that you should add labels next the inputs so the user knows what they do.

Now, on your next page, which does NOT need to be nextpage.php, but rather WHATEVER you want, as long as it matches the action of the form, do this....
<?php
if (isset($_POST['to'], $_POST['subject'], $_POST['body'])) {
mail($_POST['to'], $_POST['subject'], $_POST['body']);
} ?>

ALL that does is check if the fields weren't blank when submitted, then sends an email to the person from the to field, with the subject from the subject field and with a message from the body field.
There is no security validation or anything complex to the message.
You can do a lot more if you want.
Just look at php.net for the BASIC ways to manipulate strings (aka text variables)

Also, the mail function supports extra things, like the from attribute, and reply-to and other things.
Look at php.net for more info.


------------------------
However, if all you want is a free form mailer.... look here.... use google....
http://www.google.com/search?q=form+mailer
look for something hosted on their server that you connect to using the action (use THEIR page as the next page)
maybe this http://www.hostedscripts.com/formmailer.html
------------------------

ckydoofy13
09-28-2006, 05:21 AM
great thanks man for that makes since... for the most part, but I think Ill get it thanks for all your help!! If i have anymore questions or i get stuck be ready...lol thanks again!!!

djr33
09-28-2006, 05:46 AM
Sure.

php is confusing at first, but it ends up making sense. Really, this stuff isn't complicated. it's just new.

ckydoofy13
09-29-2006, 02:46 AM
so i found out that my server doesn't understand php so im going to try the mailer way. I got a mailer and have it all set up and have it set up to send there but for some reason I get this message when I tried to test it...

http://i11.photobucket.com/albums/a184/ckydoofy13/Untitled-1.gif


I thought I did it right?

djr33
09-29-2006, 05:27 AM
Two possibilities:
1. Something, like you password, was wrong when you set it up. Fix that. Not sure how. Just follow the directions.
2. If that doesn't work, just find another mailer. there are plenty.

ckydoofy13
09-29-2006, 07:19 PM
SWEET it works now!! I was missing a few codes that where need. such as where it needs to be sent my email and another type of routing number! thanks so much for all the help!!!!

alexliv
09-30-2006, 07:08 AM
You can use this site i'm part of:
http://www.formlogix.com
It enables you to create forms quickly and easily, publish them and then manage the data entered.
this tool is completely free and it hides all the "complicated" stuff needed to create and manage form data