Solved

Email Confirmation

Posted on 2014-02-03
5
398 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
[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 110

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 110

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 34

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
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 the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

690 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