PHP Help :(

Soldato
Joined
8 Oct 2005
Posts
4,184
Location
Midlands, UK
Hi,

First off i have hardly used php at all, so go easy on all the jargan :)

All I need is a very very simple PHP script that will collect the contents of a form from my site and send it to an email address i specify. I'm not worried about any complex validation or anything like that. If anyone can help, well, i'll owe you a cookie! :)

thanks
 
This sort of thing? It's very simple, no need for nasty scripts.
Code:
<html>
<head>
<?php

$boxone = $_POST["boxone"];
$anotherbox = $_POST["anotherbox"];

$message = '
<html>
<head>
  <title>Title of message</title>
</head>
<body>' . $boxone . '<br>' . $anotherbox . '</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
   
// Additional headers
$headers .= 'To: Your Name <toaddressgoeshere>' . "\r\n";
$headers .= 'From: Your name <[email protected]>' . "\r\n";

mail(To name, "Email subject", $message, $headers);
</head>
<body>Email sent</body>
</html>
May or may not work, ask if you don't understand. Good luck :)
 
QUOTE=joeyjojo]This sort of thing? It's very simple, no need for nasty scripts.
Code:
<html>
<head>
<?php

$boxone = $_POST["boxone"];
$anotherbox = $_POST["anotherbox"];

$message = '
<html>
<head>
  <title>Title of message</title>
</head>
<body>' . $boxone . '<br>' . $anotherbox . '</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
   
// Additional headers
$headers .= 'To: Your Name <toaddressgoeshere>' . "\r\n";
$headers .= 'From: Your name <[email protected]>' . "\r\n";

mail(To name, "Email subject", $message, $headers);
</head>
<body>Email sent</body>
</html>
May or may not work, ask if you don't understand. Good luck :)[/QUOTE]


Thanks for the replies. For the above code, can i test it using say 3 of my fields, as i have several on the actual page....
 
robmiller said:
Won't work and is horrifyingly insecure sorry joeyjojo
He asked for "a simple script", I provided :p

Seriously though what's wrong with it? Get's values from the form, puts them in an email and sends.

The fact that it doesn't work is another matter :D
 
with regards to security, you're not cleaning any of the input. for emails, use htmlentities so that javascript won't be allowed to from the email generated. can't think of anything else off the bat, but i always stripslashes from user input, too.

as for being a little less simplistic, some sort of verification to stop it being spammed might be a good idea.
 
robmiller said:
Won't work and is horrifyingly insecure sorry joeyjojo

Well as the site is only a bit of a project i'm not too worried about security. I gave up anyway after trying the preg_math function, but the pattern syntax really started to annoy me (and make my head hurt :( ) so i just need a very very simple script, that just sends the contents of a form to a specified email - nothing more or less :)

Hopefully, the one that guy provided will work, not tried yet :)
 
Yeah fair points. Thankfully it's not for anything important though, just a quick and dirty solution.

Just looked up htmlentities, you say that's used so "javascript won't be allowed to from the email generated". You mean javascript won't run in the email? Or javascript cant be used to breach security?

Verification would be good, but I have no idea about the actual application for the code, so not a lot I can do really :rolleyes:

Should be fairly straightforward suarve. Whatever your text boxes etc. are called go in $_POST["boxone"] Then just set up $message to contain the email you want to send.
 
I've posted simple secure PHP mailing scripts about 4000 times on this forum, why can I not find any of the posts by searching. Meh.

I'll write you a script and then put it somewhere safe so that can be pointed to every time this question comes up. Voila c'est finit.
 
It's replacing characters that people use to insert additional headers. You know all those viagra and ciallis emails that are flying around? 90% of them will be from header injection on some web-based email form such as a blogs 'contact me' form, just like the one you are making :p
 
Back
Top Bottom