Solved

Add responder to PHP Form

Posted on 2010-11-09
5
283 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
[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
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 110

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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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.

739 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