5 Replies - 571 Views - Last Post: 04 January 2013 - 04:38 AM Rate Topic: -----

#1 istore221  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 136
  • Joined: 11-December 11

php send form data as a email

Posted 04 January 2013 - 01:44 AM

im very new to php i have a form

Name : _______________
Contact Number : ____________________
Comment : _________________________

if the user click submit i want to get all the details via email
so far i wrote this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php

	$user_name = $_POST["NameBox"];
	$user_contact = null;
	$user_contact=$_POST["ContactBox"];
	$comment = $_POST["msgbox"];
	
	if($user_contact==null)
	{
		$user_contact = "Not provided";
		
	}
	
	
	$to = "myemail@domain.com";
	 $subject = "Message From Web";
	 $body = "Contact name is = $user_name | Contact number is = $user_contact | user comment is = $comment";
	 
	 mail($to, $subject, $body);
	 
	 header( 'Location:confirmation.html ' ) ;
	 
	
	
	

?>


</body>
</html>


when i submit the form i can't get the e-mail (because i don't have any mail server)
i want to know is there any fault in my code??
another thing is how do i get mail to me without any password
simply i want to know will it work ?
thanks

Is This A Good Question/Topic? 0
  • +

Replies To: php send form data as a email

#2 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 30
  • View blog
  • Posts: 218
  • Joined: 25-April 11

Re: php send form data as a email

Posted 04 January 2013 - 01:51 AM

why do you do this??
13 $user_contact = null;
14 $user_contact=$_POST["ContactBox"];

otherwise i do not see any errors... this should work.

what do you mean with "get mail without password"? you don't have to specify any passwords to send mails...
Was This Post Helpful? 0
  • +
  • -

#3 istore221  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 136
  • Joined: 11-December 11

Re: php send form data as a email

Posted 04 January 2013 - 01:56 AM

View PostAnthonidas, on 04 January 2013 - 01:51 AM, said:

why do you do this??
13 $user_contact = null;
14 $user_contact=$_POST["ContactBox"];

otherwise i do not see any errors... this should work.

what do you mean with "get mail without password"? you don't have to specify any passwords to send mails...


13 $user_contact = null;
14 $user_contact=$_POST["ContactBox"];

if the user not provide the contact it remain at null its works fine
if i upload this site into a web server am i able to get form data to my mail ?

This post has been edited by istore221: 04 January 2013 - 01:57 AM

Was This Post Helpful? 0
  • +
  • -

#4 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 30
  • View blog
  • Posts: 218
  • Joined: 25-April 11

Re: php send form data as a email

Posted 04 January 2013 - 02:45 AM

even if you do not define $user_contact as null it remains null in PHP if $_POST["ContactBox"] is void. but ok this is not a problem, just an information ;)

yes you are... just give it a try.
Was This Post Helpful? 0
  • +
  • -

#5 istore221  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 136
  • Joined: 11-December 11

Re: php send form data as a email

Posted 04 January 2013 - 03:39 AM

View PostAnthonidas, on 04 January 2013 - 02:45 AM, said:

even if you do not define $user_contact as null it remains null in PHP if $_POST["ContactBox"] is void. but ok this is not a problem, just an information ;)/>

yes you are... just give it a try.


thank you for your help..god bless you !!
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3001
  • View blog
  • Posts: 10,393
  • Joined: 08-August 08

Re: php send form data as a email

Posted 04 January 2013 - 04:38 AM

This is always bad:
$x = $_POST['x'];


There is no reason to copy from one variable to another. Try something like:
if(!empty($_POST['NameBox'])) {
  // Your code here.
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1