Confirmation Email PHP Sender
Hello,
I am trying to get this form to send a confirmation email to the user saying thank you and some other things but I can not get it to send the email to the user only me. Here is the php code:
PHP Code:
<?php
//print "this is the last record";
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "info@mywebsite.com";
$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'];
// create 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);
//NEW\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//Create the variables to be used in the mail
$to=$_POST['email'];
$subject="Email Confirmation";
$message="This is a confirmation email";
//Use the mail function to send the confirmation email
mail($to,$subject,$message);
//print $_GET["email"];
//print "it worked";
die();
?>
Thank you
PHP Contact Form Confirmation 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 Code:
<?php
$email_to = "info@mywebsite.com";
$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();
?>
Thank you
Contact Form W/ Confirmation Email?
Hello,
I have been trying to make a basic form with a First Name, Last Name, Email, and Invitation Code fields. Then once the submit button has been clicked it will send me the info they entered and there email will get a "Thank you" email. The main problem with this is the template that I am using, It doesn't want to work with random codes. I was using a very confusing Ajax / JS way to make the email send but no luck with the confirmation. So I am starting from scratch and seeing that I cant seem to find any help online about confirmations I though I would ask here. I want to keep it basic so I can easily edit the code for other forms that I may need. The template is in HTML but the index page is linked to every other HTML page using the code in the index.html file head tag for every HTML page.
Here is the template that I am using:
http://www.renklibeyaz.com/rightnow/
Thank you and any help is much appreciated.
Try this Validation Code - Tests for valid email address
Here is a php function that you can use for validation in your script - place it at the bottom (There are others, of course, and I may have gotten some or all of it from Ilovejackdaniels.com):
Code:
// check to see if email is valid
function validEmail($email) {
$isValid = true;
$atIndex = strrpos($email, "@");
if (is_bool($atIndex) && !$atIndex) { $isValid = false; }
else {
$domain = substr($email, $atIndex+1);
$local = substr($email, 0, $atIndex);
$localLen = strlen($local);
$domainLen = strlen($domain);
if ($localLen < 1 || $localLen > 64) { $isValid = false; } // local part length exceeded
else if ($domainLen < 1 || $domainLen > 255) { $isValid = false; } // domain part length exceeded
else if ($local[0] == '.' || $local[$localLen-1] == '.') { $isValid = false; } // local part starts or ends with '.'
else if (preg_match('/\\.\\./', $local)) { $isValid = false; } // local part has two consecutive dots
else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { $isValid = false; } // character not valid in domain part
else if (preg_match('/\\.\\./', $domain)) { $isValid = false; } // domain part has two consecutive dots
else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) {
// character not valid in local part unless local part is quoted
if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) { $isValid = false; }
}
if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) { $isValid = false; } // domain not found in DNS
}
return $isValid;
}
You use it something like this, so at the top of your php script that gets the data from the html page, it should have:
Code:
<?php
// first clean up the input values
foreach($_POST as $key => $value) {
if(ini_get('magic_quotes_gpc'))
$_POST[$key] = stripslashes($_POST[$key]);
$_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));
}
Then after that, we test all the input, and if there is something we don't like, we send it to the web browser:
Code:
// test input values for errors
$errors = array();
if(strlen($name) < 2) {
if(!$name) { $errors[] = "You must enter a name."; }
else { $errors[] = "Name must be at least 2 characters."; }
}
if(!$email) { $errors[] = "You must enter an email."; }
else if (!validEmail($email)) { $errors[] = "You must enter a valid email."; }
if($errors) {
// output errors to browser and die with a failure message
$errortext = "";
foreach($errors as $error) {
$errortext .= "<li>".$error."</li>";
}
die("<span class='failure'>The following errors occured:<ul>". $errortext ."</ul></span>");
}
Then, since everything looks good, we can finally send the email! So send it here.