PHP Contact Form Confermation Email?

Hello,
I am trying to make this contact form send an confirmation email to the user just saying thank you for registering. I have tried several ways and can not get it to work. It always sends me an email but nothing to the users email.

This is the PHP sender file code I have been trying to set up:

[php]<?php

$email_to = "[email protected]";
$email_subject = "Registration";
 
     $email_message .= "First Name Entered: ".$_GET["fname"]."\n";
	 
     $email_message .= "Last Name Entered: ".$_GET["lname"]."\n";
	 
     $email_message .= "Email Entered: ".$_GET["email"]."\n";
	 
      $email_message .= "Invitation Code: ".$_GET["email1"]."\n";

$ip=$_SERVER['REMOTE_ADDR'];

$email_message .= "IP ADDRESS: ". $ip."\n";
 
$ip=$_ENV['REMOTE_ADDR'];

$to=$_POST['email'];

$subject="Email Confirmation";

$message="This is a confirmation email";

$subject .= "Test Email"."\n";

$email .= "Email Entered: ".$_GET["email"]."\n";

$sendto = $_POST['email']."\n";

//email headers
$headers = 'From: '.$_GET[“email”]."\r\n".
'Reply-To: '.$_GET[“email”]."\r\n" .
‘X-Mailer: PHP/’ . phpversion();

@mail($email_to, $email_subject, $email_message, $headers);

@mail($sendto, $subject, $message);

die();

?>[/php]

Thank you

First thing why are you passing all the information via GET??? Your mail function’s syntax is ok but make sure are you receiving any value in the $_POST[‘email’] variable?? Just try to echo it out first to see, if it’s working or not.

Hi itskater,

It looks like you’re close, but there are a few duplicate variables and your mail functions aren’t allowing any error checking. I’m not sure about your $_GET methods either… I would try it like this, and see if you’re able to get both messages:

[php]<?php
$ip=$_SERVER[‘REMOTE_ADDR’];
$email_to = "[email protected]";
$email_subject = “Registration”;
$email_message .= “First Name Entered: “.$_POST[“fname”].”\n”;
$email_message .= “Last Name Entered: “.$_POST[“lname”].”\n”;
$email_message .= “Email Entered: “.$_POST[“email”].”\n”;
$email_message .= “Invitation Code: “.$_POST[“email1”].”\n”;
$email_message .= “IP ADDRESS: “. $ip.”\n”;

$subject .= "Email Confirmation";
$message = "This is a confirmation email";
$subject .= "Test Email"."\n";
$email .= "Email Entered: ".$_POST["email"]."\n";
$sendto = $_POST['email']."\n";
 
 
//email headers
$headers = 'From: '.$_POST["email"]."\r\n".
'Reply-To: '.$_POST["email"]."\r\n" .
'X-Mailer: PHP/' . phpversion();
echo (mail($email_to, $email_subject, $email_message, $headers) ? "Sent to mywebsite": "failed sending to website");
echo (mail($sendto, $subject, $message) ? "Copy sent to " .$sendto : "failed sending to " . $sendto);
die();

?>[/php]

Hello billthecat,
I tried that code but I only revieve the email to my email address not the user and the email shows up like this:

First Name Entered:
Last Name Entered:
Email Entered:
Invitation Code:

Without the info.

I am also using PHP in the head of the HTML index page like this:

[php]function signup_step_1(){
// alert(‘content div’);
// alert(request_content_id);
var myTextField1 = document.getElementById(‘fname’).value;
var myTextField2 = document.getElementById(‘lname’).value;
var myTextField3 = document.getElementById(‘email’).value;
var myTextField4 = document.getElementById(‘email1’).value;
//alert(myTextField);
var divid = “div_layers”;
var random_value = Math.round(Math.random()*1000000);
url = ‘form-sender-vip.php?random=’+random_value+’&fname=’+myTextField1+’&lname=’+myTextField2+’&email=’+myTextField3+’&email1=’+myTextField4+’&blank=0’;
//alert(url);
// The XMLHttpRequest object

var xmlHttp;
try{
xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
}
catch (e){
try{
xmlHttp=new ActiveXObject(“Msxml2.XMLHTTP”); // Internet Explorer
}
catch (e){
try{
xmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
catch (e){
alert(“Your browser does not support AJAX.”);
return false;
}
}
}

// Timestamp for preventing IE caching the GET request

fetch_unix_timestamp = function()
{
return parseInt(new Date().getTime().toString().substring(0, 10))
}

var timestamp = fetch_unix_timestamp();
var nocacheurl = url+"?t="+timestamp;

// The code…

xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
//alert(xmlHttp.responseText);
alert('Thank you for joining us! Be sure to check your email for a membership confirmation and for information on our daily prize giveaway. As a member you now have access to special offers in your area as well as access to event invitations. Thank you again for joining us and goodluck in our drawing! ');
//document.getElementById(‘main_reg_form’).innerHTML=xmlHttp.responseText;
//document.getElementById(‘email_1’).value = ‘’;
//document.getElementById(‘f_name’).value = ‘’;
//document.getElementById(‘l_name’).value = ‘’;
//setTimeout(‘refreshdiv()’,seconds*1000);
}
}
xmlHttp.open(“POST”,nocacheurl,true);
xmlHttp.send(null);
}[/php]

Then the HTML page is linked to another HTML page that has the form like this:

[php]

PRELAUNCH REGISTRATION

  <br />

First Name:

        </td></tr>
       <tr><td>
        <label for="lname"><p>Last Name:</p></label></td><td>
		<input class="required dFormInput" type="text" id="lname" name="title[]" value="" />
		
	</td></tr><tr><td>
		<label for="email"><p>Email Address:</p></label></td><td>
		<input class="required dFormInput" type="text" id="email" name="title[]" value="" />
		
        
	</td></tr><tr><td>
		<label for="email"><p>Invitation Code:</p></label></td><td>
		<input class="required dFormInput" type="text" id="email1" name="title[]" value="" />
		
	</td></tr><tr><td colspan=2 align=right>
		
		<img src="buttonsubmit.png" onmouseover="this.src='buttonsubmit2.png'" onmouseout="this.src='buttonsubmit.png'"onclick="signup_step_1();">
	</td></tr></table>[/php]

Ok, so this changes things a bit…

Your first bit of code is javascript, not php, and it’s using your form elements to post (via GET) to the ‘form-sender-vip.php’ file. Which I assume is the PHP file that I’d commented on previously.

Now…I hate to say it, but I would really suggest changing the way you’re going about this. The whole idea of using XMLHttpRequest objects is a pain to implement, and even harder to troubleshoot. Check out the jQuery library, where a simple ajax post looks like this:
[php]
// Assign handlers immediately after making the request,
// and remember the jqxhr object for this request
var jqxhr = $.post(“example.php”, function() {
alert(“success”);
})
.done(function() { alert(“second success”); })
.fail(function() { alert(“error”); })
.always(function() { alert(“finished”); });[/php]

Thank you, the problem is that this template is set up a bit different than anything I have seen. A basic form wont work so I had a different programer code just the forms who said he tried many things so I duplicated it and everything worked. All I tried to do by adding extra code was make it grab the already existing code and send a second email. Is this possible through the already existing code?

Sponsor our Newsletter | Privacy Policy | Terms of Service