The modal form below gets stuck on submitting.... It also doesn't actually send the message to my email. I am relatively new to PHP, but I assume this problem pertains to my sendmessage.php file(below). For whatever reason, the tutorial states to not apply an action. What coud I be doing wrong?
Just FYI, my header contains scripts to jquery.fancybox.js?v=2.0.6 and ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
sendmessage.php file:
<?php
$sendto = "jjaylad#me.com";
$usermail = $_POST['email'];
$content = nl2br($_POST['msg']);
$subject = "New Feedback Message";
$headers = "From: " . strip_tags($usermail) . "\r\n";
$headers .= "Reply-To: ". strip_tags($usermail) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;charset=utf-8 \r\n";
$msg = "<html><body style='font-family:Arial,sans-serif;'>";
$msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>New User Feedback</h2>\r\n";
$msg .= "<p><strong>Sent by:</strong> ".$usermail."</p>\r\n";
$msg .= "<p><strong>Message:</strong> ".$content."</p>\r\n";
$msg .= "</body></html>";
if(#mail($sendto, $subject, $msg, $headers)) {
echo "true";
} else {
echo "false";
}
?>
Contact form code:
<form id="contact" name="contact" action="#" method="post">
<label for="email">Your E-mail Address:</label>
<input type="email" id="email" name="email" class="txt">
<br>
<label for="msg">Inquiry:</label>
<textarea id="msg" name="msg" class="txtarea"></textarea>
<button id="send">Send E-mail</button>
</form>
The form action should point to sendmessage.php
<form id="contact" name="contact" action="sendmessage.php" method="post">
<label for="email">Your E-mail Address:</label>
<input type="email" id="email" name="email" class="txt">
<br>
<label for="msg">Inquiry:</label>
<textarea id="msg" name="msg" class="txtarea"></textarea>
<button id="send">Send E-mail</button>
</form>
I think you may be missing a file.
I get a 404 error when submitting. http://www.jjayladslair.com/sendmessage.php does not exist.
Double check the filenames?
*edit:
Just noticed that you are in fact using $.ajax to process the form. It's most definitely a case of a missing file, or incorrect filename. The 404 error causes a jQuery exception which then stops the execution of the Javascript function.
That's why the form gets stuck on submit.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
So I am trying to make a contact form for my website but i keep getting the internal server error 500. If anyone could look through the code and tell me if I am doing anything wrong that would be great. Thanks!
HTML name is index.html:
<form method="post" action="send_contact.php">
<p class="full-row">
<label for="name">Your Name:</label>
<input type="text" id="name" name="name">
</p>
<p class="full-row">
<label for="email">Email:</label>
<input type="text" id="email" name="email">
</p>
<p class="full-row">
<label for="subject">Subject:</label>
<input type="text" id="subject" name="subject">
</p>
<p class="full-row">
<label for="message">Message:</label>
<textarea name="message" id="message" rows="6"></textarea>
</p>
<input id="submit" class="mainBtn" type="submit" name="send" value="Send Message" onClick="">
</form>
PHP name is send_contact.php:
<?php
// Contact subject
$subject ="$subject";
// Details
$message="$detail";
// Mail of sender
$mail_from="$user_mail";
// From
$header="from: $name <$mail_from>";
// Enter your email address
$to ="example#example.com";
$link = "<script>window.open('confirm.html')</script>";
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
header('confirm.html');
}
else {
echo "ERROR";
}
?>
To get variable values in PHP, use $_POST['variableName']
for example to fetch this:
<input type="text" name="email">
You will need this:
$email= $_POST['email'];
<?php
// Contact subject
$subject = $_POST['subject'];
// Details
$message=$_POST['message'];
// Mail of sender
$mail_from=$_POST['email'];
// From
$header="from: ".$_POST['name']." <".$_POST['email'].">";
// Enter your email address
$to ="example#example.com";
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
header('Location: confirm.html');
}
else {
echo "ERROR";
}
?>
Also here are additional headers to help your email going in the inbox rather than the junk box:
$to = "webtest#website.com";
$subject = "Test Email";
$message = "Test Email";
// normal headers
$num = md5(time());
$headers = "From: Me <me#website.com>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=".$num."\r\n";
$headers .= "--$num\r\n";
// This two steps to help avoid spam
$headers .= "Message-ID: <".time()." TheSystem#".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";
// With message
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$message."\n";
$headers .= "--".$num."\n";
#mail($to, $subject, $message, $headers);
Cheers!
You are sending the form with post so in php you can access it like this $name = $_POST['name'].
You can access the data sent through the associative array [$_POST][1], like so:
$subject = $_POST["subject"];
HTML:
<form method="post" action="send_contact.php">
<p class="full-row">
<label for="name">Your Name:</label>
<input type="text" id="name" name="name"/>
</p>
<p class="full-row">
<label for="email">Email:</label>
<input type="email" id="email" name="email"/>
</p>
<p class="full-row">
<label for="subject">Subject:</label>
<input type="text" id="subject" name="subject"/>
</p>
<p class="full-row">
<label for="message">Message:</label>
<input type="text" name="message" id="message"/>
</p>
<input id="submit" class="mainBtn" type="submit" name="send" value="Send Message"/>
</form>
PHP:
//Check if the values requested were provided
if (isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["subject"]) && isset($_POST["message"])) {
$name = $_POST["name"];
$email = $_POST["email"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$header = "from: $name <$email>";
$to = "example#example.com";
if (mail($to, $subject, $message, $header)) {
header("Location: confirm.html");
} else {
echo("Error");
}
}
?>
As others have suggested, check your error logs if you're still running in to trouble.
So I have built my website and I planned on using a php based contact page to send emails to my email address I made this and I receive an e-mail but no content or summary...
so here is my html:
<form action="Php/sendemail.php" method="POST">
<div id="form-inner">
<input type="text" class="input" name="name" id="name" placeholder="Name">
<input type="email" class="input" name="email" id="email" placeholder="E-mail">
<textarea class="input textarea" name="message" id="message" placeholder="Your message here"></textarea>
<input type="submit" class="button" value="Send message" id="button">
</div>
</form>
and here is my php:
$subject = "Contact form submitted!";
$to = 'email#example.com';
$body = <<<HTML
$message
HTML;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $message, $headers);
header('Location: /Contact.php');
?>
I really do not understand why this is happening if you can please help ! Thnaks
This is because you are not geeting the value from the $_POST superglobal:
$body = <<<HTML
$message
HTML;
should be:
$message = $_POST['message'];
$body = <<<HTML
$message
HTML;
Of course there are other ways to do this like just putting $_POST['message']; in the message body but this illustrates how to get the submitted form values.
(You will also want to do things like clean up (i.e. trim(), etc) the submitted values and also defend against header injections as well).
I'm writing to create a contact form on my website and then get the information sent to my inbox, however it is not working whatsoever. Please take a look at my code below (PHP is not my thing) and let me know where i've gone wrong.
Here's the PHP script:
<?php
$to = 'example#gmail.com';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$tel = $_POST['tel'];
$project = $_POST['project'];
$range1 = $_POST['range1'];
$range2 = $_POST['range2'];
$body = <<<EMAIL
Hi, my name is $name.
I'd like to discuss the possibility of working together on a $project.
My budget for the project is £$range1 and I would like to complete the project within $range2 Month(s).
Additional Information:
$message
Regards, $name
<hr>
$name
$email
$tel
EMAIL;
$header = "From: $email";
if($_POST['send']){
mail($to, $subject, $body, $header);
$feedback = 'Thank you for your message, we will get back to you shortly.';
}
?>
And here's the HTML form:
<form id="form_id" name="form_name" action="" method="post">
<div>
<input type="text" name="name" id="name" placeholder="Name" required/>
</div>
<div>
<input type="email" name="email" id="email" placeholder="Email" required/>
</div>
<div>
<input type="tel" name="tel" id="tel" placeholder="Phone" required/>
</div>
<div>
<select required id="project">
<option selected>Select type of project…</option>
<option value="Responsive Website">Responsive Web Design</option>
<option value="Graphic Design">Graphic Design</option>
<option value="Motion Graphics">Motion Graphics</option>
</select>
</div>
<div>
<label for="range1">Budget: </label>
<input type="range" name="range1" id="range1" min="400" max="2000" step="50" value="6" required onchange="rangevalue.value=value"><output id="rangevalue">400</output>
</div>
<div>
<label for="range2">Timeframe: </label>
<input type="range" name="range2" id="range2" min="1" max="12" step=".5" value="1" required onchange="rangevalue1.value=value"><output id="rangevalue1">1</output>
</div>
<div>
<label for="message">Additional Information: </label><br/>
<p>(Please use this space to tell us about your company, the main objectives of the proposed website and anything else you think might be useful)</p>
<textarea name="message" id="message" rows="5" cols="30" placeholder="Message" required></textarea>
</div>
<div>
<input type="submit" name="submit" value="submit" />
</div>
</form>
<p id="feedback"><?php echo $feedback; ?></p>
Thanks for the help. FYI this can be achieved easily with WordPress through Contact Form 7 (or a similar plugin).
<input type="submit" name="submit" value="submit" />
You have to change this line to:
<input type="submit" name="send" value="submit" />
if($_POST['send']){
actually checking if submit button is clicked...
And, yes - if html and php are on different pages, you have to set proper form action link...
I think you should take a look at this or this, be aware that despite W3Schools may serve as a basics tutorial because of the friendly-user examples, always complement with other resources look here why.
Then you can take a look at this answers, this is just because you need some more basis to understand everything you are doing.
I can't see your $_POST['send'] name in the form, or it's just too late and I'm tired:
Don't know, but maybe, you want this in your form before the submit:
<input type="hidden" name="send" >
Then:
I already posted this answer HERE, but here it is:
First i think your missing some headers look at those
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
2nd check if its true or false when calling the mail function
if( mail($email_to, $email_subject, $email_message, $headers)!==true)
{
die('Fail to send');
}
die('Success');
}
You should take a look at the isset() function to make sure all your variables are set from the form.
I'm by no means a web designer/coder, but I have enough general knowledge to get my website going. Just a simple portfolio website.
I'm having some problems with my contact form though. It's strictly CSS, HTML and PHP but when I put in the information (name, email and message) to test it, it sends me an email with those field headings, but no content. For example, the email displays as;
Name:
Email:
Message:
Even when filled out with information.
I have a feeling it's something small and a stupid error, so any help is greatly appreciated!
HTML
<div id="contact-area">
<form method="post" action="contactengine.php">
<input type="text" name="Name" id="Name" placeholder="Name"/>
<input type="text" name="Email" id="Email" placeholder="Email"/>
</form>
</div>
<div id="contact-area2">
<form method="post" action="contactengine.php">
<textarea name="Message" placeholder="Message" rows="20" cols="20" id="Message"></textarea>
</form>
<div id="submit-button">
<form method="post" action="contactengine.php">
<input type="submit" name="submit" value="SUBMIT" class="submit-button" />
</form>
</div>
</div>
PHP
<?php
$EmailFrom = "contact#brettlair.ca";
$EmailTo = "contact#brettlair.ca";
$Subject = "Contact Form";
$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.htm\">";
}
?>
You have your form fields in one form, and the submit button in another. They need to be in the same form.
<form method="post" action="contactengine.php">
<input type="text" name="Name" id="Name" placeholder="Name"/>
<input type="text" name="Email" id="Email" placeholder="Email"/>
</div>
<div id="contact-area2">
<textarea name="Message" placeholder="Message" rows="20" cols="20" id="Message"></textarea>
<div id="submit-button">
<input type="submit" name="submit" value="SUBMIT" class="submit-button" />
</form>
$Name = Trim(stripslashes($_POST['Name']));
There is no Trim function, should be trim (lowercase).
I'm not receiving mails on the email mail#example.com. Below is my form code and my send-mail.php code. Can anyone help me with this cause everything seems working great bu i'm not receiving any emails. I'm using localhost as the server.
Contact form:
<form id="contactForm" action="#" method="post">
<p>Email us by filling in the form below. Make sure you fill in the message and all fields.</p>
<fieldset>
<div>
<input name="name" id="name" type="text" class="form-poshytip" title="Enter your name" />
<label>Name</label>
</div>
<div>
<input name="web" id="web" type="text" class="form-poshytip" title="Enter your surname" />
<label>Surname</label>
</div>
<div>
<input name="email" id="email" type="text" class="form-poshytip" title="Enter your email address" />
<label>Email</label>
</div>
<div>
<textarea name="comments" id="comments" rows="5" cols="20" class="form-poshytip" title="Enter your comments"></textarea>
</div>
<!-- send mail configuration -->
<input type="hidden" value="mail#example.com" name="to" id="to" />
<input type="hidden" value="Enter the subject here" name="subject" id="subject" />
<input type="hidden" value="send-mail.php" name="sendMailUrl" id="sendMailUrl" />
<!-- ENDS send mail configuration -->
<p><input type="button" value="Send" name="submit" id="submit" /> <span id="error" class="warning">Message</span></p>
</fieldset>
</form>
<p id="sent-form-msg" class="success">Form data sent. Thanks for your feedback.</p>
<!-- ENDS form -->
and here is the send-mail.php
<?php
//vars
$subject = $_POST['subject'];
$to = explode(',', $_POST['to'] );
$from = $_POST['mail#example.com'];
//data
$msg = "NAME: " .$_POST['name'] ."<br>\n";
$msg .= "EMAIL: " .$_POST['email'] ."<br>\n";
$msg .= "WEBSITE: " .$_POST['web'] ."<br>\n";
$msg .= "COMMENTS: " .$_POST['comments'] ."<br>\n";
//Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;
//send for each mail
foreach($to as $mail){
mail($mail, $subject, $msg, $headers);
}
?>
$_POST['subject'];
$_POST['to'];
$_POST['myemail#gmail.com'];
$_POST['name'];
$_POST['email'];
$_POST['web'];
$_POST['comments'];
I didn’t find any of these elements in your form. That's the reason why nothing is happening.Try
echo '<pre>';
print_r($_POST);
This will give you the posted array when the form is submitted.
i have some suggestion.if u have kept the 'to' address as hidden in the form then why cant u try keeping it directly in sendmail function and in $from you try to keep
<?php
$to="kurtfarrugia92#gmail.com";
$from =$_POST['field_name'];
// not the mail id because i didn't see any field with name as "kurtfarrugia92#gmail.com"
?>
You cannot use this function to send mail from localhost. I am not sure but you should try PHP mailer for this task.