Solved

Email Confirmation

Posted on 2014-02-03
5
383 Views
Last Modified: 2014-02-04
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
Comment
Question by:DS928
5 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39831238
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
 

Author Comment

by:DS928
ID: 39831290
Then how would I just open up a div.  Like a popup?
0
 
LVL 5

Accepted Solution

by:
Martin Tarlink earned 500 total points
ID: 39831466
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39832055
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
 
LVL 33

Expert Comment

by:Slick812
ID: 39833843
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn how to count occurrences of each item in an array.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now