send mail

M

mewizard

Guest
Hi, im in desperate need to send some info supplied in a form, to an e-mail address...

I would rather send some info from textboxes rather than using a form itself to my address.

If its easier to store it in a MySQL database then I shall do that, I just need to know how please.... :)




I also need to know, if theres a way of adding a Button, which deletes the HTML document its on....
 
S

Shocko

Guest
In php, the mail() function is easy to use, and useful :)

IIRC:
int mail ( string recipient, string subject, string body ) ;

There's also a 4th argument, which is a string containing specific headers. Look at the php manual for detailed/correct:))) info.
 
M

mewizard

Guest
was hoping some one would just, 'do it for me' :p :cool: :) :rolleyes:
 
S

Shocko

Guest
*sigh*

Code:
<?php
/* mailhandler.php */

$mailAddy = "Someone@Somewhere.sum";
$subject = "WebForm Info";

$body = "The following info was received:\n\n";
$body =+ "Input One - \n $input1\n\n";
$body =+ "Input Two - \n $input2\n\n";
$body =+ "Input Three - \n $input3\n\n";
$body =+ "EOF";

$headers = "From: $theirName <$theirMail>\n";

if( mail( $mailAddy, $subject, $body, $headers) == FALSE)
    print("Sorry, there was an error sending the form data");
?>

Code:
<form method="POST" action="mailhandler.php">
Your Name :
<input type="text" name="theirName" size=25 value=""> 

Your eMail address :
<input type="text" name="theirMail" size=25 value=""> 


Some info :
<input type="text" name="info1" size=50 value=""> 

Some more info :
<input type="text" name="info2" size=50 value=""> 

Yet more info :
<input type="text" name="info3" size=50 value=""> 


<input type="submit" value="  Submit  " border=0>
</form>
If that isn't enough to get you started, then you don't deserve a mail script.

Note: Any errors in that code are not an accurate reflection of my knowledge of php, nor my coding efficiency :p
 
M

mewizard

Guest
any reason why it always sends me


0


in the email?
 
S

Shocko

Guest
Yes. It seems i used the name "infoX" in the html form, but "inputX" in the php. Just change to one to the other.

Oh, and those assignments should be '+=', as opposed to '=+'. My php is piss poor - So shoot me :rolleyes:
 
S

Shocko

Guest
Code:
<?php
/* mailhandler.php */

$mailAddy = "Someone@Somewhere.sum";
$subject = "WebForm Info";

$body = "The following info was received:\n\n";
$body += "Input One - \n $info1\n\n";
$body += "Input Two - \n $info2\n\n";
$body += "Input Three - \n $info3\n\n";
$body += "EOF";

$headers = "From: $theirName <$theirMail>\n";

if( mail( $mailAddy, $subject, $body, $headers) == FALSE)
    print("Sorry, there was an error sending the form data");
?>

Code:
<form method="POST" action="mailhandler.php">
Your Name :
<input type="text" name="theirName" size=25 value=""> 

Your eMail address :
<input type="text" name="theirMail" size=25 value=""> 


Some info :
<input type="text" name="info1" size=50 value=""> 

Some more info :
<input type="text" name="info2" size=50 value=""> 

Yet more info :
<input type="text" name="info3" size=50 value=""> 


<input type="submit" value="  Submit  " border=0>
</form>

As they say, Knowledge is power. You may think this only refers to mi5 type chaps, however it applies to everyday life. If you don't know html and possibly php, then you can't publish on the web. Obviously there's lots of WYSWYG editors around now, however that isn't a real solution. Look at PCs in general - MS made computing piss easy, but those who don't understand how their PC works, will run downloaded attachments, and generally do stupid things.

Knowing, and understanding, are the keys to life, and also the gateway to enjoying using a computer, imho :)
 
M

mewizard

Guest
does the submit button have to be in the form?
 
S

Shocko

Guest
How else would the information be submitted? :)

Presumably the mail script now works?
 
M

mewizard

Guest
i havent tried, im just trying to interegate it into my site.... v tricky :p

especially when i need to 'design' it
 
M

mewizard

Guest
oi, watch it b4 i.......... laugh ;)

tis a very delicated, complex, and secret project im doing which is very clever! ;) :p ;) :p ;) :p
 
T

Teaser

Guest
Make sure you have named the php file correctly (mailhandler.php).

In example that Shocko did, the web server needs to have register_globals turned on (set in php.ini). If not, then for every variable in mailhandler.php that refers to one of the <inputs> in the html form, you need to put post $_POST['name_of_input_field'] . So instead of $text1, it should be $_POST['text1'] .

( If $_POST[] stuff complains, use $HTTP_POSTED_VARS[] instead ).

When the $body is built, he used += . I'm not sure if this is ok, but if it doesn't complain then I'll assume it is - but .= is a more logical operator to use (maybe that's just me though :eek: ).

$body = "blah" ;
$body .= " green tomato sauce" ;

By the way: http://uk.php.net/manual
 
S

Shocko

Guest
Aha, you are entirely correct. '+=' Would most certainly be a mathmatical operator...
 
T

Tempy_Incursion

Guest
Just wondering......hoping this is all working now.....what do people think of $_POST instead of $HTTP_POST_VARS? For those running the majority of the scripts only the latter is specified. The former is useful as register_globals isn't needed to be turned on now. (correct? :confused: )

In Java/JavaScript of course you use += for both strings and integers - unusual that.
 
O

old.Scarenius

Guest
You know, I always found that feature kinda pointless. I mean, unless they give you their email you don't even know how it's from. Not to mention the little double/triple clicking the submit button.

Wait... For a variable in PHP an addition a period.
Code:
$body = "The following info was received:\n\n";
$body .= "Input One - \n $info1\n\n";
$body .= "Input Two - \n $info2\n\n";
$body .= "Input Three - \n $info3\n\n";
$body .= "EOF";

Also you could do:
Code:
$body = "The following info was received:\n\n";
$body = "$body Input One - \n $info1\n\n";
$body = "$body Input Two - \n $info2\n\n";
$body = "$body Input Three - \n $info3\n\n";
$body = "$body EOF";

But I'm not 100% sure on the last one, I didn't test it..
 
S

Shocko

Guest
Aye, either of those would be correct i suppose...

As for the lack of an email, just ask them, and if you need a reply address, use regexp to check the results...
The best thing to do, is set their email as the reply-to, so that you don't have to mess when it comes to emailing the guy who submitted the form.
I used:
$headers = "From: $theirName <$theirMail>\n";
However, i reckon:
$headers = "From: Webform <not@need.ed>\nReply-To: $theirName <$theirMail>\nReturn-Path: <$theirMail>";
Would be better, since it would be clear that it'd come from the form, and it would also eleviate any problems with Return-Path being set as the hosted box's admin account, or something similar :)
 
O

old.Scarenius

Guest
Then there's always the idea of a message board, or a guestbook with private messaging. Building one of those message boards in PHP and keeping it completely file based is bloomin' tough. The guestbooks are rather easy. In fact I kinda prefer keeping those file based....
 
T

Tempy_Incursion

Guest
Yes an entire file-based board is damn hard as I've done one before and then did a MySQL version which is in use now.....guestbooks are pretty easy to do either file or MySQL-based.
 

Users who are viewing this thread

Similar threads

S
Replies
6
Views
634
wyrd_fish
W
O
Replies
6
Views
520
Tempy_Incursion
T
O
Replies
1
Views
401
old.Massive M
O
O
Replies
3
Views
553
old.SmegHead
O
O
Replies
10
Views
512
old.©h®°n°
O
Top Bottom