Solved

Email Confirmation

Posted on 2014-02-03
5
394 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 109

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 109

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Understanding mobile browsers 9 65
Create CSS Animation for Page Transitions 4 26
000webhost.com default error log 1 28
showing loader for php/mysql/ajax live search 13 25
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

777 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