Can't get form to work - php

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).

Related

Trying to send an email with PHP from HTML form resulting in an HTTP Error 405

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?

My HTML contact form to PHP mail isn't working [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I have a decent understanding of HTML and CSS but completely novice when it comes to PHP. I've scouted the net and tried this out with multiple different tutorials, however I can't seem to tailor the php code to work with my contact page's email form. (www.richseeley.com/contact)
Ultimately, I would like this form to confirm the message being sent with a pop up window, without leaving the page, but so far I can't even get it to work in the most basic sense.
At present, it is echoing the "thank you for using our mail form", however the email isn't sending.
Here is the html coding for my contact form:
<div id="form-main">
<div id="form-div">
<form class="form" id="form1" action="scripts/test.php" method="post" enctype="text/plain">
<input name="name" type="text" class="feedback-input" placeholder="Name" id="name" />
<input name="email" type="text" class="feedback-input" id="email" placeholder="Email" />
<textarea name="message" class="feedback-input" id="message" placeholder="Message"></textarea>
<input type="submit" value="SEND" id="button-blue"/>
</form>
</div>
</div>
And here is the PHP code that I have most recently been trying to work with:
<?php
//send email
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
mail("r*******#gmail.com", $name,
$message, "From:" . $email);
echo "Thank you for using our mail form";
?>
I appreciate that this is a fairly simple problem I am trying to solve, but I've spent several hours with no success, and I really don't want to have to compromise the design of my work/website, and end up using something less stylised, as a basic tutorial would provide.
The only way I could think of doing it would be something like:
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
echo <p>Are you sure you want to do this?</p>
<form action="send_mail.php" method="post">
<input type="submit" name="ok" value="OK" />
<input type="submit" name="cancel" value="Cancel" />
</form>
?>
and in send_mail.php:
<?php>
//send email
if (isset($_POST['ok'])) {
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
mail("richsee******#****.com", $name,
$message, "From:" . $email);
echo "Thank you for using our mail form";
}
}
if (isset($_POST['cancel'])) {
header('Location: didnt_confirm.html");
}
?>
Also, your php seems wrong and vulnerable, but all you're asking is for a confirmation ;)
If you're concerned about vulnerability (header injections), you can read this.

Javascript Form Submit with Email Action?

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

Contact Form PHP not being sent to email

Hello i have a contact form PHP from a theme i purchased. I've been trying to make a customized form with it but with no luck. Tried changing the variables around to work for the one i made myself but it is not being sent to the email i want the information to go to.
This is what i have in my HTML
<form id="" action="application/application.php" method="post" class="validateform" name="send-contact">
<div id="sendmessage">
Your message has been sent. Thank you!
</div>
Youtube Channel Name <br> <input type="text" name="youtubename" placeholder="* Enter Your YouTube Name">
<div class="validation"></div>
First Name <br> <input type="text" name="firstname" placeholder="* Enter Your First Name">
<div class="validation"></div>
Last Name <br> <input type="text" name="lastname" placeholder="* Enter Your Last Name">
<div class="validation"></div>
Your Paypal Email Address <br> <input type="text" name="paypal" placeholder="* Enter Your Paypal Email">
<div class="validation"></div>
Your YouTube Email Address <br> <input type="text" name="youtubeemail" placeholder="* Enter Your YouTube Email">
<div class="validation"></div>
Skype <br> <input type="text" name="skype" ``placeholder="* Enter Your Skype Name">
<div class="validation"></div>
<button class="btn btn-theme margintop10 pull-left" type="submit">Submit Application</button>
</form>
And for my PHP i have the following;
<?php
include 'config.php';
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
if($post)
{
$youtubename = stripslashes($_POST['youtubename']);
$firstname = stripslashes($_POST['firstname']);
$lastname = stripslashes($_POST['lastname']);
$paypal = stripslashes($_POST['paypal']);
$youtubeemail = trim($_POST['youtubeemail']);
$skype = stripslashes($_POST['skype']);
$error = '';
if(!$error)
{
$mail = mail(WEBMASTER_EMAIL, $subject, $message
"From: ".$firstname." <".$youtubename.">\r\n"
."Reply-To: ".$youtubeemail."\r\n"
."X-Mailer: PHP/" . phpversion());
if($mail)
{
echo 'OK';
}
}
}
?>
And in my config.php i have
<?php
// To
define("WEBMASTER_EMAIL", 'Support#XvinityNetwork.com');
?>
I'm not very savvy with HTML and i have a member of my staff that does this however has had an emergency issue to attend to this and i need to get this contact form up and running. I do have the default form that came with the theme and it works perfectly so im guessing i've done something wrong here. Would appreciate the help!
A notable error is you are missing a comma between $message and headers:
$mail = mail(WEBMASTER_EMAIL, $subject, $message, // Here
"From: ".$firstname." <".$youtubename.">\r\n"
."Reply-To: ".$youtubeemail."\r\n"
."X-Mailer: PHP/" . phpversion());
You have few syntax errors. A good redactor was solving your problem in a minute.
First of all the "skype" input - it has two quotes in it. Remove it. Second, in the mail function, you adding undefined $message, with no operator (such as dot) to random text. if $message containing something, place "." after it, and if not, just delete it. And if you meant to add headers, just add comma after the $message.

Do not understand why my Contact Form isn't sending emails

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/

Categories