Javascript, HP reload after alert wihout URL - php

I have an html form within a flash site. The form is php processed. Help me fix the php file so that after processing the form, the php returns the user to the flash page and reloads the html form. I tried a window.location in the php to send to the page but that did not work. It results in a white rectangle within the html code area (maybe frame but I'm not sure). How can I get just that html form reloaded? I do not want to load the entire page using a URL because that is too slow and I cannot replicate the flash state. BTW, below is a stripped down version of the code to simplify.
URL:
http://www.wix.com/efficertain/efficertainaccounting/accounting
Form Code:
Name
Phone
Best time to call
PHP Code:
$mail_to = 'info#efficertain.ca';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_phone."\n";
$body_message .= 'Message: '.$field_when;
$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 = 'http://www.wix.com/efficertain/efficertainaccounting/accounting';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to info#efficertain.ca');
window.location = 'http://www.wix.com/efficertain/efficertainaccounting/accounting';
</script>
<?php
}
?>

You should not use window.location here as it will reload the whole browser window. Try to use document.location and you will need to pass it the URL of your form instead of the URL for the whole page as you only want to reload the iframe content. So your URL would be http://www.flashquix.com/embeds/fb4c83282b9342aa83952e74ad33dfdd?wrap=no&gzip=true&bg=transparent according to the example above.
document.location = 'http://www.flashquix.com/embeds/fb4c83282b9342aa83952e74ad33dfdd?wrap=no&gzip=true&bg=transparent';

You are already putting new content on the page.. just follow the logic and make that content your form.
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to info#efficertain.ca');
</script>
// INSERT YOUR FORM HTML HERE AND YOU'RE GOOD TO GO

Related

Sendmail failing to send to some domains

I've got a small site set up that allows people to send a prewritten email to their representatives, by putting in their own email and their representatives email.
It's set up using sendmail, and works for sending to gmail, a personal email I have, and various other domains. However, it fails to send to the one domain that I need it to send to.
I get the following fault
<www-data#localhost.localdomain>: Sender address rejected: Domain not found
I've been looking through god knows how many things and I can't seem to figure it out seeing as it's working for everything else.
Hopefully someone can explain it. Cheers!
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_recipient = $_POST['cf_recipient'];
$subject = 'Message Regarding Cuts in the Mental Health Budget';
$body_message = 'hello';
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$headers .= 'Return-Path: '.$field_email;
$mail_status = mail($field_recipient, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We hope this will get the TDs in gear.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, make sure all boxes have been filled and try again.');
window.location = 'index.html';
</script>
<?php
}
?>
You have failed to set "envelope sender" email address used in MAIL FROM: command in SMTP sessions. It can be set by passing -f command line option to sendmail. See additional_parameters in mail documentation

How To Make 'Submit' Button Refresh Page?

On my website I have a 'Contact Us' form.
Currently, I am using a php form to have the information that has been filled out on the form to be e-mailed to my e-mail.
I wanted an echo message to come up once someone clicks on submit, but instead it's going to another page with the message there.
I just want the page to refresh.
This is the PHP Code:
<?php
//echo $emailBody;
sendEmail();
function sendEmail(){
global $emailBody, $name, $from, $fromName, $templateFile, $to, $subject;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "From: ". $from . "\r\n";
$headers .= "Return-Path: ".$from;
if (!mail($to, $subject, $emailBody, $headers)) {
} else {
echo "Your Message has been sent!we will contact back you in a short moment!";
}
}
?>
PHP will always send you a new page because it is a server side language. In order for this code to be executed when a user clicks the button and then the results shown to the user, the request must be sent to the server, executed, and then sent back to the user. The only way you can 'refresh' a page like you are requesting is to use a client side language such as javascript.
It is like this: When user clicks the submit button they are requesting that PHP process the request. This can only take place on the server. Because the request goes from user to server and then back to user, you will always get a new page.
Need a little more code, but typically when doing something like this, you would have the form submit back to iself and at the top of the php, do some isset(-form variable -) checking, if they are filled out then you can enter a function to process from there and subsequently echo a message to the user indicating success/failure.
I'd use:
<script type="text/javascript">
setTimeout(function(){location.reload();},1000);
</script>
<noscript>
<meta http-equiv="refresh" content="1" />
</noscript>
You can also specify this with a header (the meta-refresh only emulates this header):
header('Refresh: 1');
It is also nice to leave the user a message such as:
<div>If this page doesn't automatically refresh in one second click here.</div>
before you echo you can redirect to the source page with the message that you want to show up there
for example
if (!mail($to, $subject, $emailBody, $headers)) {
} else {
$myMsg="Your Message has been sent!we will contact back you in a short moment!";
header('location: yourpage');
}
and in your page you can check out if there is any message like this
if(isset($myMsg))
{
echo $myMsg; // in the place & style that you want
}
change your action
<form action="This is where your webpage goes" method="POST">
so this will send your page to google:
<form action="http://google.com" method="POST">
if you remove the action, it will reload the current page, like this:
<form method="POST">
just put your php in the same page as your <form>.
like the following
<?php
if($_POST['submit'] == 'send'){
sendEmail();
function sendEmail(){
global $emailBody, $name, $from, $fromName, $templateFile, $to, $subject;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "From: ". $from . "\r\n";
$headers .= "Return-Path: ".$from;
if (!mail($to, $subject, $emailBody, $headers)) {
} else {
echo "Your Message has been sent!we will contact back you in a short moment!";
}
}
}
//For that to work your button needs to be like this
?>
<form method="POST">
<!-- other fields here -->
<input type="submit" name="submit" value="send" />
</form>

Required alert on PHP contact form

I've been looking around for ages and haven't found an easy way of editing this code so that when the user hasn't typed anything into a required field (all of the fields are required) an alert is shown asking the user to please enter something.
Can anyone help?
<?php
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_message = $_POST['message'];
$mail_to = 'you#yourdomain.com';
$subject = 'Site Mail';
$body_message = 'From: '.$field_name."\n";
$body_message .= 'Email: '.$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('Thanks! Your email has been sent.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Sorry, something went wrong.');
window.location = 'index.html';
</script>
<?php
}
?>
You can use required attribute if you want to take advantage of html5 features.
Try this LINK. It shows a simple demo of how to use the required attribute.
This one too
PHP
<?php
$fields = array([0]=>$field_name,[1]=>$field_email,[2]=>$field_message);
foreach($fields as $field){
if !$field{
echo "Please enter a value.";
}
}
?>
Alternatively, you could use javascript validation, that would look something like this:
<script>
function formValid(){
var valid = true;
var fields = getElementByTag(input);
for (var i;i>=fields.length;i++){
if (!fields[i]){
getElementById('warning').style.display='inline'; // assuming the error message element is called 'warning'
getElementById('valid').value=1; // assuming we have an input that will indicate to the php code whether the form is validated
}
}
}
</script>
for this script we would then add to the beginning of the form-action php block:
if(isset($_POST['submit'])&&$_POST['valid']!=1){
// form action code goes here
}
use the code like below:-
$('.required').each(function(){
if($(this).val()=="")
{
alert("error");
}
});
The most common way to check for required fields is both on the client side (to inform the user) and the server side (to check the data is legit before we send it).
On the client side, at the point at which the form is submitted we should check to see if the fields are correct and ask the user to fix mistakes. There are a bunch of great helper libraries available to do this, a couple of the more common libraries are http://parsleyjs.org/ and http://jqueryvalidation.org/ both use jQuery and have easy examples to get started.
On the server side, as some commenters have noted, your current script is vulnerable to header injection and other nasty stuff. You might want to switch to using a library such as swiftmailer which will prevent a lot of bad stuff happening. Here is a really simple example of how to send email http://swiftmailer.org/docs/sending.html
To add server side validation to you example, as simple approach would be to check the values of $_POST['name']; before calling $mailer->send($message);

Contact form: AJAX and jQuery animation and coding structure

I'm having this problem. Look at this: http://santz.net/index.contacto.html
Try sending whatever and see what happens (it's mine, I recieve it, send whatever no problem...). (It leaves the page, shows a dialog that says thanks for contacting us... and it redirects you to the same page). I HATE THIS!!!
I'm looking fore some AJAX and jQuery code that after the message is sent, it clears the form and opens a dialog (the common one... like the typical loggin boxes) and that fades the page and that show some "x" content...
The thing is that I don't know how to do any of this things and I'm driving crazy! If you could give me the code and tell me where to put it or just give a tutorial for noobs or something like that it would be great...
I leave here the PHP code I'm using:
<?php
$field_name = $_POST['php_name'];
$field_email = $_POST['php_email'];
$field_phone = $_POST['php_phone'];
$field_message = $_POST['php_message'];
$field_sender = 'alpha#hotmail.com';
$mail_to = 'gama#hotmail.com.ar';
$subject = 'Mensaje via Santz.net de '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Phone: '.$field_phone."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_sender."\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('Gracias por contactarse, en breve, me pondre en contacto.\n\nSantz Design | www.santz.net');
window.location = 'index.contacto.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('El envio fallo. Por favor, envie un mail directamente a info#santz.net');
window.location = 'index.contacto.html';
</script>
<?php
}
?>
Try change this:
window.location.assign('http://www.santz.net/');
instead of:
window.location = 'index.contacto.html';
Showing error message on the same page, follow this example:
Add validation message in fieldset instead of js popup
And for a modal windows, use a plugin like this one:
http://www.mywebdeveloperblog.com/my-jquery-plugins/modalpoplite
Demo:
http://www.mywebdeveloperblog.com/projects/modalpoplite/demo/
saludos ;)
Why dont you use jQuery
$('input[type="submit"]').click(function(e){
e.preventDefault();
$.ajax({
type: "POST",
url: contact.php,
data: $('#contact-form"').serialize();,
success: function() {
//modal
}
});
});
something along those lines would be the ajax way of submitting your form and then pop up a window to the user saying thanks please view my form to get an idea just without popup

in php, how to send the html tag to mail

<script type="text/javascript">
var head= 23;
</script>
<?php
$h="<script language='javascript'> document.write(head);</script>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=ISO-8859-1" . "\r\n";
$mail_from='summa#yy.co.in';
$name="husssain";
$headers.="From: $name <$mail_from>";
$con="Welcome to world";
$to ="aaaa#gmail.com";
$send_contact = mail($to,$con,$h,$headers);
?>
then i send the $h to my mail id but i recieve only this <script language='javascript'> document.write(head);</script>
Consider output buffering. Better yet, consider designing your script so that the contents of the message come from a proper template.
And you realize that JavaScript is highly unlikely to run within a received email, right?
Programatically, you can't do that.
The PHP code renders before the Javascript on the page. In short, the PHP is handled first then the Javascript is written to the page. You need to have the Javascript send to a page or use AJAX to call a mail page.

Categories