I am trying to make a email send in a pop up on my site that you can see with the link below:
http://www.madaxedesign.co.uk
However it redirects perfectly to the thank you message however after it has redirected it does not implement the PHP. Below I have shown the PHP, HTML and Jquery used for this contact form.
HTML:
<form id="submit_message" class="hide_900" action="/send.php" method="post">
<div id="NameEmail">
<div>
<label for="name">Name*</label>
<input type="text" title="Enter your name" name="name"/>
</div>
<div>
<label for="email">Email*</label>
<input type="text" title="Enter your email address" name="email"/>
</div>
</div>
<div id="MessageSubmit">
<div>
<textarea maxlength="1200" title="Enter your message" name="message"></textarea>
<label for="message">Message</label>
</div>
<div class="submit">
<input type="submit" value="Submit"/>
</div>
</div>
</form>
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "maxlynn12#gmail.com";
$subject = "Email From Madaxe";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header('Location: /thanks.html');
exit();
?>
Jquery:
$('form#submit_message').live('submit', function() {
$('#popup').load('/thanks.html');
return false;
});
I was wondering if anyone could quickly look and see if I am missing anything obvious that I can quickly fix or even point me in the right direction.
Thanks
Your jQuery is interfering.
I think this might help, using AJAX to post your form: jQuery Ajax POST example with PHP
You do not need to your jquery code. actually it prevents your default action form action=send.php. and it does not pass your inputs to send.php
$.live() is deprecated in jQuery 1.9 and that's what you appear to be using. Please either downgrade or use an alternative function like .submit().
$('#submit_message').submit(function (e) {
e.preventDefault();
$('#popup').load('/thanks.html');
}
Also, it is crucial that you sanitise your $_POST inputs before using them for your e-mail headers, otherwise a hacker can inject bad things into your headers.
if you are trying to send mail through localhost you need to change some setting in php.ini file. Refer below link to do this.
http://blog.techwheels.net/send-email-from-localhost-wamp-server-using-sendmail/
Related
So I wanted to make a contact form for a website that can actually send emails, but ended up with this error :
Here's my html code:
<div class="contact-fast">
<div class="contact-form">
<form id="contact-form" method="POST" action="contact-form-handler.php">
<input name="name" type="text" class="form-control" placeholder="Your Name" required> <br>
<input name="email" type="email" class="form-control" placeholder="Your Email" required> <br>
<textarea name="message" class="form-control" placeholder="Message" rows="8" required></textarea> <br>
<input type="submit" class="form-control submit" value="SEND MESSAGE">
</form>
</div>
</div>
And here's my PHP code:
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = 'skeremobiel#gmail.com';
$email_subject = 'New Mail From Website';
$email_body = "Username: $name.\n".
"User Email: $visitor_email.\n".
"User Message: $message.\n";
$to = "said444b#gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
if ($visitor_email!=NULL) {
mail($to,$email_subject,$email_body,$headers);
}
header("Location: http://127.0.0.1:5500/social.html");
die()
?>
Here's how my page looks like before and after submitting the form:
I think the problem is that when i click on the submit button i get directed to 127.0.0.1:5500/contact-form-handler.php (as you can see in the last image in my question). It doesn't execute the php file, but it just opens it.
Any help would be appreciated!
Many things can go wrong.
Make shure php error reporting is on. Google for that.
Try to find where the error code is coming from by reducing your problem.
For instance, comment out mail() and see if it works.
Or replace your php code by a simple text to see if the code runs, if the text appears on your browser screen.
Or Google for error 405. You will learn it is an http error, something in the data exchange between your browser and the server.
Do you have characters before <?php because if you have, the server will not be able to output the HTTP header any more.
Is your php file located at the webserver root and called contact-form-handler.php?
im using this contact form below. When I was running it on my local machine it was working. But on my server if the form fails it does the right thing and goes to fail.php but when all the fields are filled it goes to send_contact2.php after clicking send instead of success.php
This is the send_contact2.php
if (empty($_POST['name'])
|| empty($_POST['number'])
|| empty($_POST['email'])
|| empty($_POST['messagearea'])
){
header('Location: fail.php');
}
else {
$name = $_POST['name'];
$number = $_POST['number'];
$email = $_POST['email'];
$messagearea = $_POST['messagearea'];
$to = 'example#gmail.com';
$subject = "Website Message: Contact form";
$message = '$messagearea';
$headers = "From: WebsiteMessage";
mail($to, $subject, $message, $headers);
header("Location: success.php");
}
?>
This is my form
<form name="form1" method="post" action="send_contact2.php">
<input name="name" type="text" placeholder="Your Name"/> <br/>
<input name="email" type="email" placeholder="Your Email"/> <br/>
<input name="number" type="tel" placeholder="Your Number"/> <br />
<textarea name="messagearea" cols="" rows="" id="messagearea" placeholder="Your Message"/></textarea> <br/>
<input name="sumbit" type="submit" value="SEND" id="button2" />
</form>
I have this setting in my cPanel
Any help would be greatly appreciated
if the page stay on send_contact2.php it is because, header("Location: success.php") do not redirect. read this post, it could help. Php header location redirect not working
In my opinion PHP must be outputing some text (char, error or warning?) or you have used a char before <?php in your send_contact2.php file. That's why header is not working. Remember that header() must be called before any actual output is sent.
OP here, managed to sort it in the end
Was a mail server issue, so if anyone in the future gets this problem check your php settings on your hosting and make sure it allows mail() and make sure you set up an email address where you're sending the email to on your server.
thanks to everyone that helped me debug
I've searched through the forums and found a lot of threads on this topic but can't seem to find the correct answer or solution for my problem.
I've got a contact form which I can't seem to get working.
HTML:
<form action="php/index.php" id="contact-form" method="post" name="form">
<div>
<label>
<span>Naam: (verplicht)</span>
<input name="vname" placeholder="Uw naam" type="text" tabindex="1" required>
</label>
</div>
<div>
<label>
<span>Email: (verplicht)</span>
<input name="vemail" placeholder="Uw e-mail adres" type="email" tabindex="2" required>
</label>
</div>
<div>
<label>
<span>Telefoon:</span>
<input name="vphone" placeholder="Telefoon nummer" type="tel" tabindex="3">
</label>
</div>
<div>
<label>
<span>Bericht: (verplicht)</span>
<textarea name="msg" placeholder="Uw vraag of opmerking" tabindex="4" required></textarea>
</label>
</div>
<div>
<input id="send" name="submit" type="submit" value="VERZENDEN">
</div>
</form>
<!-- /Form -->
And here is the PHP code, I replaced my e-mail adress in the form with MY EMAIL for obvious reasons.
<?php
if(isset($_POST['submit'])) {
$name = $_POST['vname'];
$remark = $_POST['msg'];
$from_add = $_POST['vemail'];
$to_add = "MY EMAIL";
$subject = "Your Subject Name";
$phone = $_POST['vphone'];
$headers = 'From: $from_add';
if ($phone != null){
$message = "Naam:$name \n Opmerking: $remark \n mijn telefoon nummer is $phone";
mail($to_add,$subject,$message,$headers);
}else{
$message = "Naam:$name \n Opmerking: $remark";
mail($to_add,$subject,$message,$headers);
}
}
?>
Ow I am using XAMPP to run a localhost, perhaps that could be the problem but I'm not sure.
using the php mail driver aint good for several reasons ,
u can instead try something call phpmailer http://phpmailer.worxware.com which will teach u a better way of doing things like that without frustration ,also incase later u wanted to use a php framework u will feel right at home because they will mostly be using the same syntax.
note that sending mails at first may take some time ,maybe even hours b4 u get anything ,for that u can use something like a fakesmtp https://nilhcem.github.io/FakeSMTP/ to catch the emails.
I had that same problem with a horrible server which doesn't send emails.
So I used a code that connects to a gmail account and sends the email from there.
try this tutorial:
http://coded-words.tumblr.com/post/6936532107/configure-gmail-as-smtp-in-xampp-to-send-mail
Edit 23.12.2014:
Do you have something like this in your code?
<?php
$message = "The mail message was sent with the following mail";
$headers = "From: youremail#gmail.com";
mail("youremail#gmail.com", "Testing", $message, $headers);
?>
(source: http://jiansenlu.blogspot.co.il/2014/10/php-mail-function-using-gmail-account.html)
If you do have this code:
Try submitting a different email address than the one you used in your code.
Sometimes it goes to the "Sent mail" in your Gmail account without actually showing you that you received a new email. (So you can check your "Sent mail" to see if there is anything over there).
So I'm building a site on the WP platform and have never come across this before, hoping someone might be able to help me out.
I have a form, that when submitted is redirected to a sent / thank you page. I'm using the wp home_url function for the redirect. When I press submit, I'm getting a 404, but the url it's redirecting to is correct and there is a page published with that permalink.
To make it weirder, if I erase the permalink in the URL bar of my browser and retype it, exactly the same, it then finds the page no problem.
Here's the form:
<form action="<?php echo home_url('/'); ?>sent/" method="POST" class="col-md-7">
<input id="name" placeholder="name:" name="name" type="text" class="form-control" required></label>
<input id="email" placeholder="email:" name="email" type="text" class="form-control" required>
<textarea id="message" placeholder="message:" name="message" class="form-control" rows="8" required></textarea>
<button id="contact-submit" type="submit" class="btn form-control">Submit</button>
</form>
NB I've tried using the actual URL instead of the wp home_url function as well, to no avail.
Just in case, here's the post commands too:
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name, $email, \nMessage: $message";
$recipient = "email#email.com";
$subject = "Contact Form Submission";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
As always, thanks in advance for any help / insight!
As it turns out this problem is due to an issue with wordpress. Wordpress does not allow you to use the name="name" - this causes a 404 and the form values are not sent. I changes the name to 'form_name' and it works perfectly now.
Thanks for your help, hope this can help someone else too!
Thanks to Tom Elliot at http://www.webdevdoor.com for the help! http://www.webdevdoor.com/wordpress/submitting-form-wordpress-redirects-404-page/
I need make this form send me a email like a contact form:
Script code:
<script type="text/javascript">
$(document).ready(function(){
$("#contactLink").click(function(){
if ($("#contactForm").is(":hidden")){
$("#contactForm").slideDown("slow");
}
else{
$("#contactForm").slideUp("slow");
}
});
});
function closeForm(){
$("#messageSent").show("slow");
setTimeout('$("#messageSent").hide();$("#contactForm").slideUp("slow")', 2000);
}
</script>
HTML CODE:
<div class="box">
<div id="contactFormContainer">
<div id="contactForm">
<fieldset>
<label for="Name">Nome: </label>
<input id="name" type="text" />
<label for="Telefone">Telefone Fixo: </label>
<input type="text" id="phone" maxlength="15" onkeypress="Mascara(this);" />
<label for="Message">Assunto:</label>
<textarea id="Message" rows="3" cols="20"></textarea>
<input id="sendMail" type="submit" name="submit" onclick="closeForm()" />
<span id="messageSent">Sua solicitação foi enviada com sucesso, por favor, aguarde...</span>
</fieldset>
</div>
<div id="contactLink"></div>
</div>
When click and close the form i need send me a email with the content of form, how to?
Some idea? thanks!
Firstly i can't see the form tags in your code. According to me you're doing this wrong and i'm sure many of our friends on stack will agree too.
Your question suggests that you basically want to receive an email with the data submitted through the form. Why don't you try the below method.
HTML
<form action="mail.php" method="POST">
<input type="text" name="fname"></input>
<input type="text" name="lname"></input>
<button>SUBMIT</button>
</form>
PHP
<?php
$firstname = $_POST['fname'];
$lastname = $_POST['lname'];
$to = "someone#example.com";
$subject = "Hello World";
$message = "Firstname: $firstname \n\n Lastname: $lastname";
$from = "sender#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
The above example is the most simplest method of sending an email. You can go advance by adding more header information and graphically formatting the email.
Go through these tutorials if you get confused.
http://www.w3schools.com/php/php_mail.asp
http://www.phpeasystep.com/phptu/8.html
And since you mentioned that you want to perform the task via javascript you can try submitting the form via ajax, refer the below tutorials
http://teachingyou.net/php/simple-php-contact-form-using-ajax/
http://www.sitepoint.com/forums/showthread.php?1055068-Send-PHP-email-using-jQuery-AJAX
Since you've tagged the question php, have a look at php's mail function. http://php.net/manual/en/function.mail.php
$to = 'you#domain.com';
$subject = 'Contact Form';
$message = '...' //concatenate the $_POST (or $_GET) variables to create this message
mail($to, $subject, wordwrap($message, 70, "\r\n");
This function requires that your server has a properly configured to send mail - see the php documentation for requirements: http://www.php.net/manual/en/mail.requirements.php