How to send form data to email id by using PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

We are using the yahoowebHostiing service for my company website, In
that one screen of the SendComments/FeedBack section is there, I'm
basically develeoper ,but yahoowebhosting not
support .asp,.aspx files, it supports PHP files,

I'm searching in JavaScript ,but not found any matter,
I'don't Know PHP.I'm having lot of pressure of higer officials.Please
help me on this.
Please give the Details of the PHP to send form data to given mail id
Name,email,phoneNo, Commnets...........thease are the fileds and by
click send it would be come to given to address mail id,
and how to run the php code, Please send the PHPCODE and Procee,I will
put it on the server


Re: How to send form data to email id by using PHP

Malli mindwave wrote:

Quoted text here. Click to load it


Welcome here from comp.lang.javascript.  

Quoted text here. Click to load it

Wise choice. But not very nice for you.

Quoted text here. Click to load it

Higher officials seldom care about 'details' like learning a new language  
from scratch. Why should they? They don't have to implement it themselfs..

Quoted text here. Click to load it

Nobody can send you complete code. Too many unknown variables.

But a good place to start: then type mail into the searchbox.

Also look at the mailfunction itself:

Browse around a little and try to implement some code yourself on your  
The usercontributed notes contain a lot of usefull information.

Basicly what you do is this (But PLEASE don't do it like this because all  
kind of ugly hackers will use your site to send spam. This is called  
header-injection. You don't want that.):

1) Receive the forminformation
2) assemble the email (body, subject, to who? etc)
3) send the email

Suppose your html page has a form with the following elements:
- email
- name
- phonenr
- comments

And when the user clicks submit, you want that those 4 elements are send to  

 // receive the posted formelements, I made up the names myself.
 $email = $_POST["email"];
 $name = $_POST["name"];
 $phonenr = $_POST["phonenr"];
 $comments = $_POST["comment"];

 // Please note that this input MUST be sanitised before using
 // but for the sake of a simple example I don't.

 $subject = "Somebody filled in a form";  
 $sendto = '';
 $body = "Hi Malli,\nSomebody filled in a form.\n\n";
 $body .= "Passed info:\n";
 $body .= "email: $email\n";
 $body .= "name: $name\n";
 $body .= "phonenr: $phonenr\n";
 $body .= "comments: $comments\n";

 // Wordwrap the body to max 70 characters a line:
 $body = wordwrap($body, 70);

 mail($sendto, $subject, $body);

 // done


That is basically all.
But be warned, even veteran PHP programmers make mistakes with emailing,  
simply because a lot can go wrong.
Like the abovementioned header-injection.
Or wrong headers set according to spamfilters, so your email never arives.  
(try sending to if you need a headache)

You might want to use a lib/class to send email.

I use HTMLMimeMail a lot, for sending emails that have both text and HTML  
content and/or attachments. (google for it if you want it)

PHP also have the PEAR packages that contain a good mail class.
Very good chances they are allready installed on your system.

Honest warning:
This might be over your head if you don't even know PHP. :-/
If you are on a tight deadline, you might consider hiring a PHP programmer  
who did this before to help you out. Setting up a basic emailprogram  
shouldn't take more than a day.

Good luck.

Erwin Moller

Quoted text here. Click to load it

Re: How to send form data to email id by using PHP

Malli mindwave wrote:
Quoted text here. Click to load it

Try googling for PHP and formmail.  There are a number of scripts out there.

Or, if you want a custom solution, I'm sure there are people available  
here at regular consulting rates.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline