| Coding Forum Problems with your code? Let's hear about it. |
07-31-2006, 03:52 AM
|
#1 (permalink)
|
|
Contributing Member
Join Date: 07-24-06
Location: UK
Posts: 149
Latest Blog: None
|
PHP: Email form
Hi guys i'm a total n00b at coding php I only know the basics i'm still learning.
Basicaly what i need is a form:
Name:
sing line text entry box
Email Address:
Single line text entry box
Then i want that form to be sent to my email via sendmail.php
but on the email sent to me i want the name of the person who sent the mail and alo their email in on sent by section so then my autoresponder can send them an email back.
This is simple know but for me its a learning process.
Thanks for any input
.~Optix~.
|
|
|
07-31-2006, 04:50 AM
|
#2 (permalink)
|
|
Contributing Member
Join Date: 07-24-06
Location: UK
Posts: 149
Latest Blog: None
|
I was wandering could a mailing list software do this? but that would mean my computer be connected to the internet all the time?
also after the submit i need the page redirected to a thank you page
.~Optix~.
|
|
|
07-31-2006, 06:27 AM
|
#3 (permalink)
|
|
Inactive
Join Date: 06-16-06
Posts: 268
Latest Blog: None
|
Hey optix,
I think the best option for you would be to look around at some autoresponder/mailing list programs like you said (I found this one: http://www.aweber.com). You wouldn't need to be connected all the time. All you would need is to sign up with them, and they'll give you some code that you could put in your website and it would show that form.
They would also let you specify what page people are taken to after they put in their email address and click the button.
The downside is that they aren't free. You'll have to spend a couple of bucks at it to make it work.
By the way do you have an autoresponder setup on your website? If you do, and you don't want to buy a mailing list program (which you should buy if you can) then I can give you a quick script which sends an email after they submit their email address and takes them to a page that you specify.
|
|
|
07-31-2006, 06:36 AM
|
#4 (permalink)
|
|
Contributing Member
Join Date: 07-24-06
Location: UK
Posts: 149
Latest Blog: None
|
Salaam.
Yes Ali that is exactly what I need. could you please code me the script
Many thanks
Wasalaam.
.~Optix~. 
|
|
|
07-31-2006, 07:48 AM
|
#5 (permalink)
|
|
Contributing Member
Join Date: 07-24-06
Location: UK
Posts: 149
Latest Blog: None
|
Ali seems to have vanished:S Is there any one else who can do the job?
.~Optix~. 
|
|
|
07-31-2006, 09:38 AM
|
#6 (permalink)
|
|
Junior Member
Join Date: 05-16-06
Location: UK
Posts: 6
Latest Blog: None
|
This is the script I'm using on a few of my websites. At the moment, like any form on a website, I'm having problems with people spamming them. One technique I have used is to not let them use an email address containing "@mydomain.com". This has cut out about 95% of the spam. I was wondering what other methods people are using?
PHP Code:
if ( $_POST['send'] ) { $Name = stripslashes(trim($_POST['name'])); $Email = trim($_POST['email']); $Subject = stripslashes(trim($_POST['subject'])); $Message = stripslashes($_POST['message']);
if ( !$Message || str_word_count($Message) > 300 ) $E_Message=true; if ( !$Email || !preg_match("/[a-z0-9_-]+(\.[a-z0-9_-]+)*@([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})/i", $Email) ) $E_Email = true;
if ( !$E_Email && !$E_Message ) { if ( !$Subject ) $Subject = 'Question';
$Sent = mail('you@example.com', $Subject, $Message, "From: \"".$Name."\" <".$Email.">");
if ( $Sent ) { echo("<p class=\"warning\">Thank you, your message has been sent. We will be in contact with you shortly.</p>\n"); unset($Name, $Email, $Subject, $Message); } } }
You can put this into sendmail.php or you can put it into the same page as the email form.
Your form should look like this.
HTML Code:
<form method="post" action="/sendmail.php">
<p>
Name<br>
<input name="name" type="text" size="45" value=""><br>
Valid Email<br>
<input name="email" type="text" size="45" value=""><br>
Subject<br>
<input name="subject" type="text" size="45" value=""><br>
Message (Max 300 Words)<br>
<textarea name="message" rows="12" cols="43"></textarea><br>
<input type="submit" name="send" value="Send">
</p>
</form>
This is the base for you, you can add error reporting if you like. You can use the variables $E_Email and $E_Message for this. It is also nice to propagate the form if there was an error so the user doesn't have to write it all again (obviously you can only do this if the form and the script is on the same page.)
|
|
|
07-31-2006, 09:46 AM
|
#7 (permalink)
|
|
Inactive
Join Date: 06-16-06
Posts: 268
Latest Blog: None
|
Hey, sorry optix. I just saw your post and I was about to code you the script but saw that Appricot already did it. Well, if you need any help later on let me know 
|
|
|
07-31-2006, 09:52 AM
|
#8 (permalink)
|
|
Contributing Member
Join Date: 07-24-06
Location: UK
Posts: 149
Latest Blog: None
|
Warning: mail() expects at least 3 parameters, 2 given in /home/cpanel/optix/public_html/test.php on line 11
  Hellpp
line 11 is
$Sent = mail('atif_Khan@hotmail.co.uk', "From: \"".$Name."\" <".$Email.">");
.~Optix~. 
|
|
|
07-31-2006, 09:54 AM
|
#9 (permalink)
|
|
Contributing Member
Join Date: 07-24-06
Location: UK
Posts: 149
Latest Blog: None
|
oh w8 it might be the extra quotation let see
|
|
|
07-31-2006, 09:57 AM
|
#10 (permalink)
|
|
Contributing Member
Join Date: 07-24-06
Location: UK
Posts: 149
Latest Blog: None
|
ok basicaly i tired it edit the script so that the only two fileds are name and email:
the php
Code:
<?
if ( $_POST['send'] )
{
$Name = stripslashes(trim($_POST['name']));
$Email = trim($_POST['email']);
{
if ( !$Subject )
$Subject = 'Free SEO';
$Sent = mail('goawayspamer@spamland.com, "From: \"".$Name."\" <".$Email.">);
if ( $Sent )
{
echo("<p class=\"warning\">Thank you, your message has been sent. We will be in contact with you shortly.</p>\n");
unset($Name, $Email);
}
}
}
?>
the html
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form method="post">
<p>
Name<br>
<input name="name" type="text" size="45" value=""><br>
Valid Email<br>
<input name="email" type="text" size="45" value=""><br>
<input type="submit" name="send" value="Send">
</p>
</form>
</body>
</html>
after taking out the extra quotation the error i get know is
Parse error: syntax error, unexpected T_CLASS in /home/cpanel/optix/public_html/test.php on line 15
and i dont get an email
Last edited by Optix : 07-31-2006 at 10:08 AM.
|
|
|
07-31-2006, 10:02 AM
|
#11 (permalink)
|
|
Junior Member
Join Date: 05-16-06
Location: UK
Posts: 6
Latest Blog: None
|
You need to have the Subject and Message there, you can leave it as an empty string if you want, but then you wont get there message just an empty email.
$Sent = mail("you@example.com", "", "", "From: \"".$Name."\" <".$Email.">");
PS. I would remove your email address from the above post if I was you. Otherwise you WILL start receiving loads of spam.
|
|
|
07-31-2006, 10:09 AM
|
#12 (permalink)
|
|
Contributing Member
Join Date: 07-24-06
Location: UK
Posts: 149
Latest Blog: None
|
Thank for the heads up
Empty email is good because the email is going to be an autoresponder so no problem there.
I shall try your edit and get back to you
Thanks again
.~Optix~. 
|
|
|
07-31-2006, 10:13 AM
|
#13 (permalink)
|
|
Contributing Member
Join Date: 07-24-06
Location: UK
Posts: 149
Latest Blog: None
|
actuly to be safe i'll have the subject.
can i have it set to whatever i want it to be?
can you tell me which line to change to what please
.~optix~. 
Last edited by Optix : 07-31-2006 at 10:42 AM.
|
|
|
07-31-2006, 10:39 AM
|
#14 (permalink)
|
|
Contributing Member
Join Date: 07-24-06
Location: UK
Posts: 149
Latest Blog: None
|
BUMP*
|
|
|
07-31-2006, 12:27 PM
|
#15 (permalink)
|
|
Inactive
Join Date: 06-16-06
Posts: 268
Latest Blog: None
|
Hiya optix,
change:
PHP Code:
$Sent = mail('goawayspamer@spamland.com, "From: \"".$Name."\" <".$Email.">);
to:
PHP Code:
$Sent = mail('goawayspamer@spamland.com', "Subject here","Any message you want to put here","From: \"$Name\"<".$Email.">");
Try it and let me know how it goes.
Edit: There was a little typo in the code, if you tried it before try it again now.
Last edited by ali_420 : 07-31-2006 at 12:31 PM.
|
|
|
07-31-2006, 12:53 PM
|
#16 (permalink)
|
|
Contributing Member
Join Date: 07-24-06
Location: UK
Posts: 149
Latest Blog: None
|
Hi Ali
Thanks for the response and it worked.
I know need a redirect to a thank you page.
Can you give me the code for that please
Thanks a bunch for your help!!
.~Optix~. 
|
|
|
07-31-2006, 02:12 PM
|
#17 (permalink)
|
|
Inactive
Join Date: 06-16-06
Posts: 268
Latest Blog: None
|
Hey,
for the redirect, replace the lines:
PHP Code:
if ( $Sent ) { echo("<p class=\"warning\">Thank you, your message has been sent. We will be in contact with you shortly.</p>\n"); unset($Name, $Email); }
with
PHP Code:
$redirectUrl='http://www.example.com/where-you-want-to-redirect.html'; if ( $Sent ) { header('location:'.$redirectUrl); die; }
P.S you want to give it a try by filling in the form and seeing if the email is actually sent etc.
Last edited by ali_420 : 07-31-2006 at 02:19 PM.
|
|
|
08-01-2006, 02:43 AM
|
#18 (permalink)
|
|
Contributing Member
Join Date: 07-24-06
Location: UK
Posts: 149
Latest Blog: None
|
Wooooooooooooooooooooooooooooooooooooooooooooooooo oooooooooooooo hoooooooooooooooooooooooooooooooooooooooo
THANKS ALI YOU ARE AMAZING!!
Rep added!
.~Optix~.
|
|
|
08-01-2006, 03:10 AM
|
#19 (permalink)
|
|
Inactive
Join Date: 06-16-06
Posts: 268
Latest Blog: None
|
I know  . Feel free to pm me if you need more help later on (which you will  )
|
|
|
08-01-2006, 03:42 AM
|
#20 (permalink)
|
|
Contributing Member
Join Date: 07-24-06
Location: UK
Posts: 149
Latest Blog: None
|
lol thanks for the offer dude. and i'll prolly take it up ;p
.~Optix~. 
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|