943,177 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 66
  • PHP RSS
Aug 31st, 2010
0

having form data sent to specified e-mail

Expand Post »
Hello again everyone..

I have a form with an e-mail input. After the user enters their e-mail, I want to have the content of the form sent to them...
The name of the form textfield for the e-mail is "email".

How could I make this happen in the php script??

thank you!
-l.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
lwaterfo is offline Offline
46 posts
since Jul 2010
Aug 31st, 2010
0
Re: having form data sent to specified e-mail
You have a submit.php page (or whatever you want to call it) with the code to send the email.

You need to post the variables from your form.

Create a subject variable with your subject in it.

Create a message variable with your message in it.

Then you add the headers, and use the mail script.

Here's an example of a script:
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $name = $_POST['name'];
  3. $email = $_POST['email'];
  4. $content = $_POST['message'];
  5.  
  6. $subject = 'Your Subject Goes Here';
  7.  
  8. $message = '
  9. <html>
  10. <head>
  11. <title>Email Response</title>
  12. </head>
  13. <body>
  14. From: '.$name.'<br>
  15. Message: '.$message.'
  16. </body>
  17. </html>';
  18.  
  19. // To send HTML mail, the Content-type header must be set
  20. $headers = 'MIME-Version: 1.0' . "\r\n";
  21. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  22.  
  23. // Additional headers
  24. $headers .= 'From: '.$email.' <'.$email.'>' . "\r\n";
  25.  
  26. // Mail it
  27. mail($email, $subject, $message, $headers);
  28.  
  29. ?>

Hope this is helpful!
Reputation Points: 10
Solved Threads: 2
Newbie Poster
jkaye is offline Offline
11 posts
since Jul 2010
Aug 31st, 2010
0
Re: having form data sent to specified e-mail
thx a lot this was helpful...one last thing, I have fields in my form that I want to display in the e-mail. how do I display the fields without using an html message? In other words, what would I place in between the single quotes below if I don't want to send an html message, but just regular text?
PHP Syntax (Toggle Plain Text)
  1. $message = ' ';
Reputation Points: 10
Solved Threads: 0
Light Poster
lwaterfo is offline Offline
46 posts
since Jul 2010
Aug 31st, 2010
0
Re: having form data sent to specified e-mail
Your message would look like:

PHP Syntax (Toggle Plain Text)
  1. $message = ''.$variable1.'\n\n'.$variable2.'\n\n';

The "\n" is a single line break, so using two is like adding a paragraph tag.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
jkaye is offline Offline
11 posts
since Jul 2010
Aug 31st, 2010
0
Re: having form data sent to specified e-mail
grab the php variables using post then create a mail function

mail($email, $subject, $message);
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pcalior is offline Offline
8 posts
since Aug 2010
Aug 31st, 2010
0
Re: having form data sent to specified e-mail
I'm having some trouble with the message string..
I keep getting an error when I try to display the variables:

PHP Syntax (Toggle Plain Text)
  1. $message = ''.$mondayweek1.'\n\n'.$tuesdayweek1.'\n\n'.$wednesdayweek1.'\n\n'.$thursdayweek1.'\n\n'.$fridayweek1.'\n\n'.$saturdayweek1.'\n\n'.$sundayweek1.'\n\n'.$mondayweek2.'\n\n'.$tuesdayweek2.'\n\n'.$wednesdayweek2.'\n\n'.$thursdayweek2.'\n\n'.$fridayweek2.'\n\n'.$saturdayweek2.'\n\n'.$sundayweek2.'\n\n';

Can you find the error in this message code?
Reputation Points: 10
Solved Threads: 0
Light Poster
lwaterfo is offline Offline
46 posts
since Jul 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Arrays
Next Thread in PHP Forum Timeline: Show content only to visitors from search engines





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC