Solved

Add responder to PHP Form

Posted on 2010-11-09
5
273 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 300 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 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 200 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 30

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now