[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 409
  • Last Modified:

Email Confirmation

I have an email form on an HTML page.  After the email is sent I want the form to disappear and the "Thank You response to appear in it's place on the same page.  How would I do this?

<form action="contactemp.php" method="post">
<table width="601" height="188" style=" border:none;">
<tr>
<td>Please Enter Your Name</td>
<td><input name="cf_name" type="text" size="50"></td>
</tr>
<tr>
<td>Your E-mail Address<br></td>
<td><input name="cf_email" type="text" size="50"></td>
</tr>
<tr>
<td height="86">Send Us A Message</td>
<td><textarea name="cf_message" cols="50" rows="6"></textarea></td>
</tr>
</table>
    
<input type="submit" value="Send">
<input type="reset" value="Clear">
</form>

Open in new window


<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = 'website@mediascrubber.com';
$subject = 'Employment'.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
	<script language="javascript" type="text/javascript">
		alert('Thank you for the message. We will contact you shortly.');
		window.location = 'contact_page.html';
	</script>
<?php
}
else { ?>
	<script language="javascript" type="text/javascript">
		alert('Message failed. Please, send an email to gordon@template-help.com');
		window.location = 'contact_page.html';
	</script>
<?php
}
?>

Open in new window

0
DS928
Asked:
DS928
1 Solution
 
Ray PaseurCommented:
This question deeply misunderstands the nature of the PHP mail command and the entire email system.  You might want to contact a professional email service company about this.  Maybe an entity like www.ConstantContact.com could help.  As written you're at the foot of a high and treacherous mountain and you need professional help, quickly, before you're caught in an avalanche!

I don't have enough time left in life to tell you all of the ways that this path can go wrong for you, but I hope you will take my advice and get professional help.  I've spent years wrestling with these issues and I promise you, they are non-value-added and enormously time consuming.
0
 
DS928Author Commented:
Then how would I just open up a div.  Like a popup?
0
 
Martin TarlinkNetwork Systems AdministratorCommented:
In email forms  I usually use switch() function to play with checking email status
You can specify var "check" that will redirect your function depend what status you will have.

switch ('check') {
    case ($_GET['check']=="check");  
    ... checking code here
    break;
    
    case ($_GET['check']=="form");
	emailform();
    break;

    case ($_GET['check']=='success')

    echo "Thank you for sending email";
			 
    break;
}

Open in new window

and the confirmation could be set like this
if ($to!== NULL) {
	mail($to, $sub, $msg, $headers);
		echo nl2br("<h2>Congratulations email was send!!</h2> ");
}

Open in new window

This is a just an idea, it is hart to write whole code because I am not sure what you try to accomplish  eg. my email file is 750 lines long

Regards
Tarlink
0
 
Ray PaseurCommented:
Then how would I just open up a div.  Like a popup?
Check out the "modal form" in the jQuery UI
https://jqueryui.com/dialog/

But make sure you thoroughly understand Client/Server protocols first!
0
 
Slick812Commented:
greetings DS928, , You say - " I want the form to disappear and the "Thank You response to appear in it's place on the same page." This is NOT the way a Normal <form> submit works, as the entire page will be refreshed with the new page that the <form> is submitted to in the normal way. . If you want to do page section refresh as "form to disappear" and a "thank You" is shown, , then I would have to use the AJAX javascript browser-server exchange. Unfortunately the Ajax coding is not so easy to understand at first, but it can be something that is very useful for today's user-friendly web sites. I guess you already know that your code example with the javascript output, will not work.
Tell us more about what you need, and there will be more suggestions for you to try.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now