Click to See Complete Forum and Search --> : Need to send a form content as Email.
vijji
11-14-2003, 03:11 PM
Hi,
I have been trying to create a form and send its contents as email. I also want the email content to be formatted the way I want it to look. Is this possible ??
Thanks,
Vijaya
Yes, but it to format it in HTML, you will need to use a server-side script (such as PHP, CGI, ASP or JSP) to send the email. It is possible to set the action attribute to mailto:user@domain.com, but no HTML formatting will be involved, and it will not work for users with Web-based email set as default (unless they've downloaded some sort of program that does that enables it). Also, it's best to send the form via enctype="text/plain" if you use the mailto: protocol.
[J]ona
vijji
11-14-2003, 03:29 PM
Hi,
Thanks a lot for your time. I did exactly what u said in ur mai. It sends a email but can u send me the code in asp or jsp (preferably) or cgi to format the text in the mail ??
Thanks,
Vijaya
I don't know ASP or JSP, as my host doesn't support either, but here is a script I made in CGI (Perl). You'll need to change a few variables to point to your sendmail and Perl executables, though... (param() contains the different field names.)
#!/usr/local/bin/perl
use CGI qw{:cgi};
my $name = param('fn');
my $name2 = param('ln');
my $email = param('em');
my $rating = param('rat');
sub Mail
{
($to, $from, $subj, $body) = @_;
$mailprog = "/usr/sbin/sendmail";
open(MAIL, "| $mailprog -t ");
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subj\n";
print MAIL $body;
print MAIL "\n";
}
Mail("you\@email.com", $email, "From your site", "You have just received a rating from someone. Here is their information:\n\nName: $name $name2\nEmail: $email\nRating of your site: $rating");
print <<END;
Content-Type: text/html\n\n
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body><p>
Name: <b>$name $name2</b><br>
Email: <b>$email</b><br>
Rating: <b>$rating</b>
</p>
</body></html>
END
[J]ona
asbjoern
11-16-2003, 10:57 PM
I have the very same problem, but since I am new to programming and scripting, I did't quite understand the first part of your solution Jona. Where do you have to put the code above the html code. And know does the form summit anything?
maybe my question is a bit basic :-)
asbjoern
The code I provided is Perl/CGI code which means it must be a .cgi or .pl script uploaded to a CGI-BIN folder on the server. If you do not have access to a server-side language, then you cannot use these scripts.
[J]ona
asbjoern
11-17-2003, 05:21 PM
well thanks for your reply [J]ona, i found another bit simpler way to do it though (I understand it better anyway) it is a php file thats look like this in the body tag.One thing though is that I would like to put the emailadress typed by the user into the senderadress when i resive the mail. I just can't figure out???
Asbjoern
<form action="" medthod="post" >
<p>
Navn <input name="textarea1" height="15" width="200"></p>
Email <input name="textarea2" height="15" width="150">
<p>
Emne <select name="textarea3">
<option value="ALLERGI" selected> Allergi
<option value="BARSEL"> Barsel
<option value="LEGETØJ"> Legetøj
<option value="MAD" selected> Mad
<option value="MAGASINER" selected> Magasiner
<option value="PLEJE" selected> Pleje
<option value="PUSLEBORD" selected> Puslebord
<option value="SIKKERHED" selected> Sikkerhed
<option value="SYGDOM" selected> Sygdom
<option value="LINKS" selected> Links
<option value="LINKS" selected> Vælg
</select></p>
<p>
Kommentar <br> <textarea name="textarea4" rows="4" cols="40"></textarea></p>
<input type=submit value=" SEND! ">
</form>
<?php
if ($textarea1 != "") {
$recipient = "your@email.com";
$subject = "Subject";
$message .= "This is the user input\n"; // \n er et linieskift
$message .= "Navn: $textarea1\n";
$message .= "Email: $textarea2\n";
$message .= "Emne: $textarea3\n";
$message .= "Kommentar: $textarea4\n";
mail($recipient, $subject, $message);
print "Your mail has been submitted";
}
?>
Change the following line...
mail($recipient, $subject, $message);
Into this:
mail($recipient, $subject, $message, "From: $textarea2");
[J]ona
asbjoern
11-17-2003, 07:31 PM
thanks a lot it works great,
asbjoern