Log In · Register

 
PHP email form thing
heyo-captain-jac...
post Aug 15 2009, 02:35 PM
Post #1


/人◕‿‿◕人\
*******

Group: Official Member
Posts: 8,283
Joined: Dec 2007
Member No: 602,927



CODE
<?php
if (isset($_REQUEST['email']))
  {
  $email = $_REQUEST['email'];
  $subject = $_REQUEST['subject'];
  $message = $_REQUEST['message'];
  mail( "example@example.com", "Subject: $subject",
  $message, "From: $email" );
  echo "Thank you.";
  }
else
  {
  echo "<form method='post' action='mailform.php'>
  Email: <input name='email' type='text' /><br />
  Subject: <input name='subject' type='text' /><br />
  Message:<br />
  <textarea name='message' rows='10' cols='40'>
  </textarea><br />
  <input type='submit' />
  </form>";
  }
?>


Someone with a brain for PHP, make sure I didn't mess that up anywhere.


The issue is when I load it in IE, all I see is the source code. But when I refresh it, everything renders properly.
 
 
Start new topic
Replies (1 - 7)
jiyong
post Aug 15 2009, 04:12 PM
Post #2


사랑해 ~ 我愛你 ♥
*****

Group: Design Staff
Posts: 825
Joined: Jan 2007
Member No: 492,587



I don't know shrug.gif The coding looks alright, and it works in Firefox.
 
Maccabee
post Aug 15 2009, 06:12 PM
Post #3


Senior Member
*******

Group: Official Designer
Posts: 5,880
Joined: Nov 2007
Member No: 593,382



Post mailform.php

So I can check it over, and so I can steal it.
 
mipadi
post Aug 16 2009, 08:18 AM
Post #4


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



Can you do multiline strings like that in PHP? I thought you had to use the HERE-doc syntax for multiline strings.
 
patokelley
post Aug 16 2009, 08:20 AM
Post #5


Newbie
*

Group: Member
Posts: 1
Joined: Aug 2009
Member No: 742,411



Are you using it in PHP or in an HTML site to hide your email address?
 
fixtatik
post Aug 16 2009, 12:31 PM
Post #6


Senior Member
******

Group: Member
Posts: 1,237
Joined: May 2008
Member No: 648,123



QUOTE(jcp @ Aug 15 2009, 06:12 PM) *
Post mailform.php

So I can check it over, and so I can steal it.

Considering it's an if-else statement, and it's sending the email in the if part of it, I'd say that is mailform.php.

It should work perfectly fine. Dead-simple, so there's really no protection against things you don't want, like people sending only an email address, or the email address being jibberish, or spam, what-have-you. Details aside, the syntax is fine and it will work.
 
heyo-captain-jac...
post Aug 16 2009, 12:38 PM
Post #7


/人◕‿‿◕人\
*******

Group: Official Member
Posts: 8,283
Joined: Dec 2007
Member No: 602,927



QUOTE(mipadi @ Aug 16 2009, 08:18 AM) *
Can you do multiline strings like that in PHP? I thought you had to use the HERE-doc syntax for multiline strings.

As far as I know, you can.
QUOTE(patokelley @ Aug 16 2009, 08:20 AM) *
Are you using it in PHP or in an HTML site to hide your email address?

I'm doing a website for a travel agency, and there is a page where you get a quote.
You put your details in the form, and it sends your details to whatever the owner ends up using as the email address. The owner replies to the email with a quote, and good times are had by all.
QUOTE(fixtatik @ Aug 16 2009, 12:31 PM) *
Considering it's an if-else statement, and it's sending the email in the if part of it, I'd say that is mailform.php.

Genius.
QUOTE
It should work perfectly fine. Dead-simple, so there's really no protection against things you don't want, like people sending only an email address, or the email address being jibberish, or spam, what-have-you. Details aside, the syntax is fine and it will work.

Yeah, it's pretty vulnerable as is. I'm going to set up something to prevent PHP injections, because that's all I really can prevent, aside from requiring an @ symbol in the email field.
 
fixtatik
post Aug 16 2009, 12:56 PM
Post #8


Senior Member
******

Group: Member
Posts: 1,237
Joined: May 2008
Member No: 648,123



QUOTE(Buttsex @ Aug 16 2009, 12:38 PM) *
Yeah, it's pretty vulnerable as is. I'm going to set up something to prevent PHP injections, because that's all I really can prevent, aside from requiring an @ symbol in the email field.
If you reaaaally want to go all-out with it, you can try email verification with a crap-load of checks. Dev Shed has a nice tutorial on this.

You might also want to change
CODE
if (isset($_REQUEST['email'])) { }
to
CODE
if (isset($_REQUEST['email'] && isset($_REQUEST['subject']) && isset($_REQUEST['message'])) { }
so they aren't getting a bunch of blank emails.
 

Closed TopicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members: