?
Solved

Web form mailer

Posted on 2009-04-13
6
Medium Priority
?
1,032 Views
Last Modified: 2012-05-06
I have no idea what I'm doing when it comes to php.  I am putting a contact form on my sister's webpage, but I have no idea how to make it take the information input by the user and send it to the email address she wanted me to use.  My hosting is on godaddy.com and they created two php files on the root directory when her hosting account was created.  It is being hosted on a Linux server.  The two php files created are webformmailer.php and gdform.php.  What additional code do I need to use to get the input to the email address?  Thanks in advance.  
<center><form method="post" action="webformmailer.php">
       Name: <input name="name" type="text"><br />
       Email: <input name="email" type="text"><br>
       Message:<br>
<textarea name="message" rows="15" cols="40"></textarea><br>
<input type="submit">
</form></center>

Open in new window

0
Comment
Question by:fuzzyjon79
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 9

Accepted Solution

by:
Mahdii7 earned 1000 total points
ID: 24134354
This is all you need to make that work:
<?php
// webformmailer.php
 
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$message = $_REQUEST['message']."\r\nSent From: ".$email;
$to = "where_you_want_to_send_it@hotmail.com";
$subject = "Web Form Email!";
 
mail($to, $subject, $message, "From: " . $email);
?>

Open in new window

0
 

Author Comment

by:fuzzyjon79
ID: 24134423
Okay, thanks.  One additional question, where would I put confirmation messages on telling the user that the message was sent successfully?  Right now, when the submit button is clicked, it jumps back to the index.html page.  I would like to display a simple message stating that the form was sent successfully.  Thanks.  
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24135992
I do this - I believe you need to log on to godaddy and set up who is the recipient:



<script type="text/javascript">
function validate(theForm) {
  if (theForm.email.value=="") {
    alert('Please enter an email address');
    theForm.email.focus();
    return false;
  }
  theForm.action="gdform.php"; // helps cut down on robots
  return true;
}
</script>
 
<form action="#" method="post" onSubmit="return validate(this)">
<input type="hidden" name="subject" value="Mail from my site">
<input type="hidden" name="redirect" value="thankyou.html">
Name: <input name="name" type="text"><br />
Email: <input name="email" type="text"><br>
Message:<br>
<textarea name="message" rows="15" cols="40"></textarea><br>
<input type="submit">
</form>

Open in new window

0
What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

 

Author Comment

by:fuzzyjon79
ID: 24138227
Okay, I've got the form working correctly now.  The only problem I have is that when the user clicks the submit button, they get no confirmation message.  What code would I add to keep them on the same page and just display a "Your message was sent successfully" confirmation message?  Also, would I add it to the webformmailer.php file or the contacts page?  
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24138341
You can use AJAX or do it the old fashioned way

Keep the script I gave you but change the action to webfommailer.php and have

<form action="#" method="post" onSubmit="return validate(this)" target="thankyouFrame">
<input type="hidden" name="redirect" value="thankyou.html">

.
.
.
<iframe src="about:blank" name="thankyouFrame" width="200" height="20"></iframe>

and in your thankyou.html have
<h2>Your message was sent successfully</h2>

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24474405
Hmm
0

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question