?
Solved

Add responder to PHP Form

Posted on 2010-11-09
5
Medium Priority
?
289 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 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

719 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