468,272 Members | 2,048 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

send data form to an e-mail!!

hello,
i want to know how to send a form data to a mail
that form ,the user enters its data and when pressing submit it sends that data to a mail
thanx.
Sep 24 '06 #1
13 3609
ronverdonk
4,258 Expert 4TB
Question now is: do you want to send just the entered data or do you want to send html to your user? Remember that some users (like myself) don't like html in their emails, so I'll just assume that you want to send text.

Next question is: do you have mail configured in your php.ini file? This is a different definition for Windows and Unix, so you'll have to know that before you start.

Having all that, you can simply create and send an email message using php's mail function (there are plenty of mailo classes around on the net, but I assume you want to use simple php for this).
The following code will show you how to accomplish this. For a more detailed explanation on the mail() function see the php documentation at PHP mail reference and mail() function

The following code shows a simple email script.
[PHP]
<?php
// email address of the adressee
$To = 'JohynDoe@hisnet.com';
// email address of the sender
$From = 'MyId@mynet.com';
// the subject of your message
$Subject = 'This is the subject text';
// the text of the message
$Message = 'Here comes the message text for the mail';
// send the mail
if (mail($To, $Subject, $Message, "From: $From")) {
echo 'Mail sent successfully';
// whatever else you want to do here
}
else {
echo 'Error when sending mail';
// whatever else you want to do now
}
?>
[/PHP]
Ronald :cool:
Sep 25 '06 #2
thanx vry much 4 that replay

but i wanna to tell u that this form contains text items that the user enters data
in it, i wanna when pressing submit send these information to the mail for example info@comp.net
Sep 25 '06 #3
Could you please put the contents of your form here and maybe the structure in which you want your e-mail to look like.
Sep 26 '06 #4
firstly thanx for the script
it is working
but i want to send
$message in a spicific format
how to do that??
when i make "<br>" to print new line it appears as html in the sent message
plz i need that urgently
Oct 1 '06 #5
ronverdonk
4,258 Expert 4TB
The mail fields should not contain <br> because that is html, and you want to send plain text.
Insert a newline at the place you want to break the text into a new line, as follows (remember to put the \n within double quotes, otherwise it will generate a separate backslash and a separate 'n'):
[PHP]$message = "This is my first text line.\nAnd this is the second.";[/PHP]
Ronald :cool:
Oct 1 '06 #6
firstly thanx for help,

i want to make the mail function sends html code
how t let it support that??
i looked at the php manual but the function used don't work
i want to let the
$Message=<a href="http://site.com">The Site</a>

but it prints the html code too not just the "The Site"

thanx in advance
Oct 3 '06 #7
heay,
when i looked at the php manual i found that headers that enabled the html code
but i face error
Warning: mail(): SMTP server response: 501 Syntax error in parameters or arguments
that is the headers i used
[PHP]$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";[/PHP]
Oct 3 '06 #8
moishy
104 100+
I use www.FormToEmail.com.
Oct 5 '06 #9
ronverdonk
4,258 Expert 4TB
The To: field is not to be stored in the headers. Why don't you see if the following very simple example (without any special headers but inclding a link reference ) works for you. It does for me. And then build it up.
[PHP]<?php
// send simple mail text with link
$to = "you@yoursite.nl";
$subject = "test example";
$message = "This is my text example.\n
Test of second line.\n
Click on http://wwww.MySite.com to notify me.";
$headers = "From: me@mysite.nl";

if (mail($to, $subject, $message, $headers))
echo 'Mail sent';
else
echo 'Error in mail function';
?>[/PHP]

Ronald :cool:
Oct 5 '06 #10
hello,
thanx ronald but i need to enable html code
as i said b4 there was error!!!!!!!!!!

how to handle that error
Oct 7 '06 #11
ronverdonk
4,258 Expert 4TB
Sorry I misunderstood. The following sample works for me. Try it out and when it works for you, add your extra addresses etc.
[PHP]<?php
$headers = "MIME-Version: 1.0\n" .
"Content-Transfer-Encoding: 8bit\n" .
"Content-type: text/html; charset='iso-8859-1'\n" .
"From: MySite@mycom.com";
$to = "you@yoursite.com";
$subj = "Here is your html";
$body = "hi <b>my friend</b>! \n\n this message uses <i>html entities</i> !";
if (!mail($to, $subj, $body, $headers))
echo 'Error';
else
echo 'Message sent';
?>[/PHP]

Ronald :cool:
Oct 7 '06 #12
I use www.FormToEmail.com.
Thank you

I think www.FormtoEmail.com is simple to use.

Thank you very much for the recommendation. Do you have any other recommendations for forms? I need a form to collect data from the user like first name, address and email. Are you able to help?

Thank you
Oct 29 '06 #13
ronverdonk
4,258 Expert 4TB
Well, you can copy the recommended code and adapt it to your needs. It is not that difficult for a programmer to just add a couple of more text fields to that form.

Also, there is another free PHP form and email script. Look at Charles Reace's site for the source at PHP Email Contact Form

Ronald :cool:
Oct 29 '06 #14

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Fatih BOY | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.