I need help in PHP form

Asked By 70 points N/A Posted on -
qa-featured

How do I make an HTML FORM to work in PHP? Am new in PHP, I designed a website with a what you see is what you get software (WYSIWYG) but now I need a form in PHP, I have written the HTML form and I have put the contact PHP script as the value for the action attribute. I have also written the code for the submitted date using PHP $_GET and $_POST. My problem is getting the mail function to work. How do I send the data to the mail using the mail function?

SHARE
Answered By 0 points N/A #190169

I need help in PHP form

qa-featured

PHP mail() function is used to send emails in PHP. Then use the following code for mail function to keep the variables in your script and to form the website.

<?php

//if "email" variable is filled out, send email

  if (isset($_REQUEST['email']))  {

 

  //Email information

  $admin_email = "[email protected]";

  $email = $_REQUEST['email'];

  $subject = $_REQUEST['subject'];

  $comment = $_REQUEST['comment'];

 

  //send email

  mail($admin_email, "$subject", $comment, "From:" . $email);

 

  //Email response

  echo "Thank you for contacting us!";

  }

 

  //if "email" variable is not filled out, display the form

  else  {

?>

 

 <form method="post">

  Email: <input name="email" type="text" /><br />

  Subject: <input name="subject" type="text" /><br />

  Message:<br />

  <textarea name="comment" rows="15" cols="40"></textarea><br />

  <input type="submit" value="Submit" />

  </form>

 

<?php

  }

?>

 

In the above code, the first part checks to see whether the email is entered or not. If present, set to ready to send. After filling the email, click submit, then page gets reload and reads the email input which you have given and sends it.

Related Questions