Solved

Add responder to PHP Form

Posted on 2010-11-09
5
284 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

630 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