Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Add responder to PHP Form

Posted on 2010-11-09
5
Medium Priority
?
293 Views
Last Modified: 2012-08-13
How would I add a simple text auto-responder to the attached code?

Thanks in advance!
<form method=post action="?">
<br />
      <span class="whitebold">Email: </span>
      <span class="whitebold">
      <?php
//set up for email info
$strTo = 'newsletter@xxx.com'; //your email here
$strSubject = 'New Registration'; //default subject 
$strBody = '';

if ($_POST['submit']) {
	
	$strEmail = trim($_POST['email']);

	//both fields are required 
	if (!$strEmail) {
		$error = 'Please input both field!<br />';
	}	
	//elseif () {//extra validate should be here. eg: validate email address
	//}
	else {
		//prepare mail body
		$strBody = <<<BODY
New registration
Email: {$strEmail}
BODY;

		//send email
		@mail ($strTo, $strSubject, $strBody,
     "From: ".$strTo."\r\n" .
     "Reply-To: ".$strTo."\r\n" .
     "X-Mailer: PHP/" . phpversion());


		//display message
		echo 'thanks for registering!';
		
	}
}
?>
      </span>
    <table width="177" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="61%" align="left"><input name="email" type="text" size="12" /></td>
        <td width="39%" align="right"><input name="submit" type="image" value="send" src="images/register.png" align="bottom" /></td>
      </tr>
  </table>
   
</form>

Open in new window

0
Comment
Question by:BrighteyesDesign
5 Comments
 
LVL 26

Accepted Solution

by:
EddieShipman earned 1200 total points
ID: 34101143
Not sure exactly what you're after, here. Auto-respond to WHOM?
To the person that filled the form?
To do that, just add this code after this line

"X-Mailer: PHP/" . phpversion());

//prepare mail body
$strBody = <<<BODY
Thanks for registering
BODY;

//send email
@mail ($strEmail, $strSubject, $strBody,
"From: ".$strTo."\r\n" .
"Reply-To: ".$strTo."\r\n" .
"X-Mailer: PHP/" . phpversion());

Open in new window

0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 800 total points
ID: 34101295
The design pattern in this article might be helpful to you.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_3939-Registration-and-Email-Confirmation-in-PHP.html

Among other things, it will help you avoid becoming an open relay for spam.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 34101942
What does wrong with anwser ID:34101143 by Author:EddieShipman? And what about Ray's article? IMHO you have received optimal answers. If you think to need something else, be more descriptive, please, and tell us what is wrong in received answer.

Cheers
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 34104183
I totally agree with what Ray has said about being an open relay. You WILL need to secure that thing.
0
 

Author Closing Comment

by:BrighteyesDesign
ID: 34104249
Cheers guys!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

963 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