471,045 Members | 1,263 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,045 software developers and data experts.

send data form to an e-mail!!

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
Sep 24 '06 #1
13 3680
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.
// 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
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
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
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
104 100+
I use www.FormToEmail.com.
Oct 5 '06 #9
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.
// 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';
echo 'Error in mail function';

Ronald :cool:
Oct 5 '06 #10
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
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.
$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';
echo 'Message sent';

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
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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.