954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP Form submit to email

HEllo i want to know how to submit form to email so that one can received all form infromation in email , if u have seen Contact pages, inquiery pages in website same as i want. Either in PHP or ASP

NitinThacker
Newbie Poster
4 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

maybe you should check previous posts. But anyway, when you submit a form(for example,form1.php), post all the variables to another page(form2.php), add those variables to another variable, say $message and use mail function to send the mail. More on mail function Here .

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

Follow the steps iam mention and if you have any confusion in understanding the code pls .get back to me


CREATING THE FORM IN PHP :


Email:

Message:

The above form will collect the user's email and message, and then pass them to the page contact.php


SENDING THE MAIL :

<?php
$to = "you@yoursite.com";
$subject = "Contact Us";
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "We encountered an error sending your mail"; }
?>

SAVE THIS FILE AS CONTACT.PHP

HEY ! YOUR ARE DONE.

------------------

CHANGE THE FORM FIELD ACCORDING TO YOUR NEEDS I HAVE USED MESSAGE BOX BUT YOU ARE FREE TO USE ANY FIELD ACCORDING YOUR USAGE. HOPE IT HELPS YOU.

thnx,

innovativeatul
Junior Poster in Training
72 posts since Dec 2007
Reputation Points: 3
Solved Threads: 0
 


Your Name :

Friend's Email Address :


<?

if (@$_POST['Send']=="Send")
{
$name=$_POST['name'];
$email=$_POST['email'];
$subject = $name. " wants you to visit this site, its cool!";
//This is the body section of the email and can be substituted for your message
$message= "Hi, \n\n" .$name. " thinks you might like to visit our website : \n\n http://www.yourdomain.co.uk \n\n\n\n\n\n\n\nNote: This message was not sent unsolicited. It was sent through a form located at http://www.yourdomain.co.uk If you believe this message was received on error, please disregard it.";
$headers = 'From: [email]webmaster@yourdomain.co.uk[/email]' . "\r\n" . 'Reply-To: [email]webmaster@yourdomain.co.uk[/email]' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
mail($email, $subject, $message, $headers);
echo "You`ve recommended our site to: $email Thanks you";
}
?>


amylawson
Newbie Poster
4 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

what is the error that you are getting ? What do you mean by cant seem to get it to work ?

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 


Your Name :

Friend's Email Address :


<?

if (@$_POST['Send']=="Send")
{
$name=$_POST['name'];
$email=$_POST['email'];
$subject = $name. " wants you to visit this site, its cool!";
//This is the body section of the email and can be substituted for your message
$message= "Hi, \n\n" .$name. " thinks you might like to visit our website : \n\n http://www.yourdomain.co.uk \n\n\n\n\n\n\n\nNote: This message was not sent unsolicited. It was sent through a form located at http://www.yourdomain.co.uk If you believe this message was received on error, please disregard it.";
$headers = 'From: [email]webmaster@yourdomain.co.uk[/email]' . "\r\n" . 'Reply-To: [email]webmaster@yourdomain.co.uk[/email]' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
mail($email, $subject, $message, $headers);
echo "You`ve recommended our site to: $email Thanks you";
}
?>


Habro
Newbie Poster
2 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

Nobody ????

Habro
Newbie Poster
2 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

could you please help me to write perfect code as per my requirement, actually, i've form details like (please refer to the attached image), please could you give me right code for the same. it will help me immense and i will be greatful to you.

Attachments form_image.jpg 15.88KB
Tarun Jain
Newbie Poster
1 post since Aug 2009
Reputation Points: 7
Solved Threads: 0
 

You have got a mail server running haven't you? I use IIS/PHP on Windows and I run Mercury Mail Server (because the IIS mail server is a bit of a mystery to me) to handle the email. I'm guessing that Apache/PHP on windows will also need a mail server.

Also, take out the <? echo $_POST['self']; ?> so that the form action is action=""

slyme
Junior Poster in Training
63 posts since Aug 2009
Reputation Points: 11
Solved Threads: 4
 

Here is my code:

Place this in your HTML code.
onSubmit="return checkemail(this)" // have a javascript function called checkemail (or change name on function and below) to check for null values.

<form method="post" name="Emailform" action="sendmail.php" target="_self" onSubmit="return checkemail(this)"> 
 
<table border="0" cellspacing="0" cellpadding="4" width="90%" id="ContactMe"> 
<tr> 
    <td width="30%"><div align="right">Name:</div></td> 
    <td width="70%"><input type="text" name="name" size="30" /></td> 
</tr> 
 
<tr> 
    <td><div align="right">Email:</div></td> 
    <td><input type="text" name="email" size="30" /></td> 
</tr> 
 
<tr> 
    <td><div align="right">Website:</div></td> 
    <td><input type="text" name="site" size="30" /></td> 
</tr> 
 
<tr> 
    <td><div align="right">Message:</div></td> 
    <td><textarea name="message" cols="40" rows="4"></textarea></td> 
</tr> 
 
<tr> 
<td>&nbsp;</td> 
    <td> 
    <input type="submit" name="submit" value="Submit" /> 
    <input type="reset" name="reset" value="Reset" /> 
    </td> 
</tr> 
 
</table> 
</form>


And now make a php file called 'sendmail.php'

<?php
$to = "YOUR EMAIL@YOUR DOMAIN.com";
$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$site = $_REQUEST['site'] ;
$subject = "Message from: $name";
$message = $_REQUEST['message'] ;
$headers = "noreply@YOURWEBSITE.com";
$body = "From: $name \n\n Email: $email \n\n Wesbite: $site \n\n Message: $message";
$sent = mail($to, $subject, $body, $headers) ;
if($sent)
{echo "<script language=javascript>window.location = 'LINK BACK TO CONTACT PAGE';</script>";}
else
{echo "<script language=javascript>window.location = 'LINK BACK TO CONTACT PAGE';</script>";}
?>


The result will be a well structured email (not sent to junk mail) with all the information from the sender.

I hope this helps all of you.
Here is my website where you can find my contact page:

If you have any comments or queries please contact me there.
I can help you with the javascript to check for null values, and help you make a method to give the user feedback when the message is sent, or not.

ptemedia
Light Poster
29 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

Hi guys, I'm to new to the web development. Kindly tell me how to send the form to my domain.

Attachments tes.png 44.64KB
Ramorchid
Newbie Poster
1 post since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

what is error on page
i am give a link that helpful to you visit here
http://www.ibdhost.com/contact/

manzarr
Light Poster
39 posts since Jul 2010
Reputation Points: 11
Solved Threads: 1
 

Why, with all of the suggestions is there no input validation or captcha. Those forms are going to be spam havens.

EverWebby
Light Poster
47 posts since Jan 2010
Reputation Points: 11
Solved Threads: 5
 

A easy and simple way to reduce some spam is to include a hidden field like this:

<form method="post" name="myform" action="example.php" target="_self" onSubmit="return verify(this)">

<table>
//other fields here

<tr style="visibility:hidden">
<td><input type="text" name="verify" size="20" value="" /></td>
</tr>

</table>
</form>


Then, onSubmit of the form, run some javascript code to check for null value in 'verify'. Since its hidden, a human cannot enter data so if the field is empty, return true and send email. A spam bot would automatically enter data so if the field is not empty, return false and do nothing or run an error message.

ptemedia
Light Poster
29 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

In the example below we first declare the variables ($to, $subject, $message, $from, $headers), then we use the variables in the mail() function to send an e-mail:

<?php
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>


or for mail example see this link ibdhost.com/contact

manzarr
Light Poster
39 posts since Jul 2010
Reputation Points: 11
Solved Threads: 1
 

Thanks..

I used this code.. but aftr hosting this pages in my site it will showing error like... 'We encountered an error sending your mail'

Please check if i did any mistake in my script..

code of form:

<form name="membership" method="post" action="contact.php" enctype="multipart/form-data">
<input name="name" type="text" id="name" size="35">
<input name="email" type="text" id="email" size="35">
<input name="profession" type="text" id="profession" size="35">
<input name="phone" type="text" id="phone" size="35">
<textarea name="comments" cols="55" rows="5" id="comments"></textarea>
<input type="submit" name="Submit" value="Submit">
</form>


code of contact.php:

<?php
$to = "vijayregonda@gmail.com";
$subject = "Contact Us";
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$profession = $_REQUEST['profession'] ;
$phone = $_REQUEST['phone'] ;
$comments = $_REQUEST['comments'] ;
$headers = "From: $email";
$sent = mail($to, $name, $phone, $comments, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "We encountered an error sending your mail"; }
?>


This is my script as u gvn... nw please suggest me to get the email of form details to my mail???

vijayregonda
Newbie Poster
1 post since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

can you pls provide me with php code for this form below


Contact Form




Name *



Enter your Name



Phone Number *




###


-



###


-



####




Email *





Address *




Street Address



Address Line 2



City



State / Province / Region



Postal / Zip Code


India
Antigua and Barbuda

Aruba,Bahamas

Barbados

Belize

Canada

Cook Islands

Costa Rica

Cuba

Dominica

Dominican Republic

El Salvador

Grenada

Guatemala

Haiti

Honduras

Jamaica

Mexico

Netherlands Antilles

Nicaragua

Panama

Puerto Rico

Saint Kitts and Nevis

Saint Lucia

Saint Vincent and the Grenadines

Trinidad and Tobago

United States

Argentina

Bolivia

Brazil

Chile

Colombia

Ecuador

Guyana

Paraguay

Peru

Suriname

Uruguay

Venezuela

Albania

Andorra

Armenia

Austria

Azerbaijan

Belarus

Belgium

Bosnia and Herzegovina

Bulgaria

Croatia

Cyprus

Czech Republic

Denmark

Estonia

Faroe Islands

Finland

France

Georgia

Germany

Greece

Hungary

Iceland

Ireland

Italy

Latvia

Liechtenstein

Lithuania

Luxembourg

Macedonia

Malta

Moldova

Monaco

Montenegro

Netherlands

Norway

Poland

Portugal

Romania

San Marino

Serbia

Slovakia

Slovenia

Spain

Sweden

Switzerland

Ukraine

United Kingdom

Vatican City

Afghanistan

Bahrain

Bangladesh

Bhutan

Brunei Darussalam

Myanmar

Cambodia

China

East Timor

Hong Kong

India

Indonesia

Iran

Iraq

Israel

Japan

Jordan

Kazakhstan

North Korea

South Korea

Kuwait

Kyrgyzstan

Laos

Lebanon

Malaysia

Maldives

Mongolia

Nepal

Oman

Pakistan

Palestine

Philippines

Qatar

Russia

Saudi Arabia

Singapore

Sri Lanka

Syria

Taiwan

Tajikistan

Thailand

Turkey

Turkmenistan

United Arab Emirates

Uzbekistan

Vietnam

Yemen

Australia

Fiji

Kiribati

Marshall Islands

Micronesia

Nauru

New Zealand

Palau

Papua New Guinea

Samoa

Solomon Islands

Tonga

Tuvalu

Vanuatu

Algeria

Angola

Benin

Botswana

Burkina Faso

Burundi

Cameroon

Cape Verde

Central African Republic

Chad

Comoros

Democratic Republic of the Congo

Republic of the Congo

Djibouti

Egypt

Equatorial Guinea

Eritrea

Ethiopia

Gabon

Gambia

Ghana

Gibraltar

Guinea

Guinea-Bissau

Cote d'Ivoire

Kenya

Lesotho

Liberia

Libya

Madagascar

Malawi

Mali

Mauritania

Mauritius

Morocco

Mozambique

Namibia

Niger

Nigeria

Rwanda

Sao Tome and Principe

Senegal

Seychelles

Sierra Leone

Somalia

South Africa

Sudan

Swaziland

United Republic of Tanzania

Togo

Tunisia

Uganda

Zambia

Zimbabwe

Country




Main Category *

Matrimonial Property Recruitment Business Personal Vehicles Announcement Astrology Classifieds Rememberance Computers Education Entertainment Marriage Bureau Obituary Retail Services Situation Wanted Tenders/Public Notice To Rent Travel Wedding Arrangements Other


Your Ad *



Enter your ad here.



Comments (if Any)






Image Verification





Please enter the text from the image:
[Refresh Image] [What's This?]





unversity top
Newbie Poster
3 posts since May 2011
Reputation Points: 10
Solved Threads: 0
 

I need to make a submit fuction on a price calculator I have made for a client, just need some advice. The URL for the form is:
http://pantherfireworks.com/NEC_calculator/calculator.html
I would only need the quantity "order" fields submitted.

Thanks,
Dean

Deanb
Newbie Poster
1 post since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

The problem might be that you are not running any mail server software like Mercury. I use Xampp and it comes with Mercury so it works for me.

prof php
Newbie Poster
13 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

Solution to all the above

READ THE Finelyconstructed MANUAL

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You