Mail not sending when submitting form - php

For some reason this form is not working and not sending out emails through submitting the form. It says the form has successfully submitted but it never sends anything. What is causing the problem? Please help.
<?php
$id = protect($_GET['id']);
$sql = mysql_query("SELECT * FROM items WHERE id='$id'");
if(mysql_num_rows($sql)==0) { header("Location: $web[url]"); }
$row = mysql_fetch_array($sql);
?>
<section class="dashboard content">
<div class="container">
<div class="row">
<div class="span12">
<h3>Contact with Owner</h3>
<?php
if(isset($_POST['do_send'])) {
$item_name = protect($_POST['item_name']);
$name = protect($_POST['name']);
$email = protect($_POST['email']);
$subject = protect($_POST['subject']);
$message = protect($_POST['message']);
if(empty($name) or empty($email) or empty($subject) or empty($message)) { echo error("All fields are required."); }
elseif(!isValidEmail($email)) { echo error("Please enter a valid email address."); }
else {
$get = mysql_fetch_array(mysql_query("SELECT * FROM admins ORDER BY id LIMIT 1"));
$admin_email = $get['email'];
$to = $admin_email;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$subjectt = $web[sitename].' - Message from '.$name;
$messaget = '<html><body><table border="0" cellspacing="2" cellpadding="2"><tr><td><span style="font-size:30px;font-weight:bold;">'.$web[sitename].'</span><br></td></tr><tr><td>You have new message from user for item. Here is message details:</td></tr><tr><td>From: '.$name.' ('.$email.')</td></tr><tr><td>Item: '.$row[name].'</td></tr><tr><td>Subject: '.$subject.'</td></tr><tr><td>Message:<br/>'.nl2br($message).'</td></tr></table></body></html>';
mail($to, $subjectt, $messaget, $headers);
echo success("Your message was sent successfully.");
}
}
?>
<form action="" method="POST">
<div class="bg-color white rounded-top">
<div class="box-padding">
<div class="control-group">
<label class="control-label" for="inputUsername">Item</label>
<div class="controls">
<input type="text" id="inputUsername" name="item_name" class="input-block-level" disabled value="<?php echo $row['name']; ?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputUsername">Your name</label>
<div class="controls">
<input type="text" id="inputUsername" name="name" class="input-block-level">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputUsername">Your email address</label>
<div class="controls">
<input type="text" id="inputUsername" name="email" class="input-block-level">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputUsername">Subject</label>
<div class="controls">
<input type="text" id="inputUsername" name="subject" class="input-block-level">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputUsername">Message</label>
<div class="controls">
<textarea name="message" class="input-block-level" rows="4"></textarea>
</div>
</div>
</div>
</div>
<div class="bg-color dark-blue rounded-bottom">
<div class="box-padding narrow-horizontal">
<div class="control-group">
<div class="controls">
<button type="submit" name="do_send" class="btn btn-primary">Send</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
The contact form is here: http://rocketraiser.com/contact/13546224#sthash.HnYyaGGz.0o0gQ4nS.dpbs
The contact form brings in the individual item name.
Please can you show me how to fix this. Thank you very much.
-Harry

Could be that the form has no action, by the looks of that code, the action should be the same URL the form is in

Related

Why isn't my PHP form working? I do receive the email but there is no content in it

PHP form on my website isn't responding well. It would be appreciated if someone could help me.
This is the HTML Code of the form
<form action="contactform.php" method="post" name="form" class="p-5 bg-white">
<div class="row form-group">
<div class="col-md-6 mb-3 mb-md-0">
<label class="text-black" for="fname">First Name</label>
<input type="text" id="fname" class="form-control">
</div>
<div class="col-md-6">
<label class="text-black" for="lname">Last Name</label>
<input type="text" id="lname" class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="email">Email</label>
<input type="email" id="email" class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="subject">Subject</label>
<input type="subject" id="subject" class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="mssg">Message</label>
<textarea name="mssg" id="mssg" cols="30" rows="7" class="form-control" placeholder="Write your notes or questions here..."></textarea>
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<input type="submit" value="Send Message" class="btn btn-primary py-2 px-4 text-white">
</div>
</div>
</form>
This is the PHP Code
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$to = "alyyashar#gmail.com";
$subject = "New email from your site!";
$fname = $_POST['fname'];
$email = $_POST['email'];
$message = $_POST['message'];
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$title = '<h3>Hello! You have received a new mail from your website!</h3>';
$body = "$title
<br/>
<b>From:</b> $fname
<br/>
<b>E-Mail:</b> $email
<br/>
<b>Message:</b>\n$message
<br/>
<br/>";
if (mail($to, $subject, $body, $headers)){
echo "<h1>Sent Successfully! Thank you"." ".$fname.", We will contact you shortly!</h1>";
} else {
echo "Something went wrong!";
}
}
?>
<br>
Back to Homepage
This is the email I receive
Screenshot of the email
When I enter information into the form and click send message, I do receive the email but there is no content in it.
The form elements have no name attributes, which is what the browser uses to send their name/value pairs to the server. So while it's posting the form, none of the values are being included.
For example, this:
<input type="text" id="fname" class="form-control">
Should be this:
<input type="text" id="fname" class="form-control" name="fname">
The same fix would need to be repeated for the remaining form elements.

PHP sending email but not getting data from HTML Form [duplicate]

This question already has answers here:
empty $_POST in PHP mail()
(2 answers)
phpmailer how to check if field is empty sintax
(2 answers)
Closed 4 years ago.
I am trying to get some data, like name, email, etc. from an HTML form and sending that data to my gmail. I am getting an email with 'You have recieved an email from .' and 'No Sender' and 'No subject' as the email details.
Here is the PHP:
<?php
if(isset($_POST['submit'])) {
$name = $_POST['first_name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['email'];
$message = $_POST['message'];
$mailTo = "tamiroffen#gmail.com";
$headers = "From: " . $mailFrom;
$txt = "You have recieved an email from " . $name . ".\n\n" . $message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.html?mailsend");
}
?>
Here is the form section snippet of the HTML:
<form action="contact_form_process.php" method="POST">
<section id="contact" class="py-3">
<div class="container">
<div class="row">
<div class="col-md-9 mx-auto">
<div class="card p-4">
<div class="card-body">
<h3 class="text-center lato-font">Please Fill Out This Form To Contact Us</h3>
<hr>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input id="first_name" name="first_name" type="text" class="form-control" placeholder="First Name">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input id="last_name" type="text" class="form-control" placeholder="Last Name">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input id="email" type="text" class="form-control" placeholder="Email">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input id="phone_num" type="text" class="form-control" placeholder="Phone Number">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<textarea class="form-control" name="" id="message" rows="10" placeholder="Message"></textarea>
</div>
</div>
</div>
</div>
<div class="card-footer">
<button type="submit" name="submit" class="btn btn-outline-success btn-block">Send</button>
</div>
</div>
</div>
</div>
</div>
</section>
</form>

Unable to send an email after clicking on submit button in php

Trying to send an email not displaying any error message or anything just refreshing the page that it.
I am trying an email through contact form but its not working.Here is the code for that. tried by doing echo but it is not working .not displaying any error as well.
contact and contactus:
<?php ob_start();
if(isset($_POST['submit'])) {
$to = "abc#gmail.com";
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$txt = $_POST['comment'];
$headers = "From: " .$email . "\r\n" .
"CC: xyz#gmail.com";
mail($to,$subject,$txt,$headers);
header("Location: contact.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>HMS System</title>
</head>
<body>
<div class="container">
<div class="page-header">
<h2>Contact Us Form</h2>
</div>
<form class="form-horizontal" action="contactus.php" method="post" role="form">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="name" placeholder="Insert your Name" id="name">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email Address</label>
<div class="col-sm-8">
<input type="email" class="form-control" name="email" placeholder="Email Address" id="email">
</div>
</div>
<div class="form-group">
<label for="subject" class="col-sm-2 control-label">Subject</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="subject" placeholder="Subject" id="subject">
</div>
</div>
<div class="form-group">
<label for="comments" class="col-sm-2 control-label">Comment</label>
<div class="col-sm-8">
<textarea class="form-control" rows="10" name="comment" style="resize:none;"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-8">
<input type="submit" value="Send Message" name="submit_contact" class="btn btn-block btn-danger" id="subject">
</div>
</div>
</form>
</section>
</article>
</div>
<div style="width:50px;height:50px;"></div>
</body>
use this
if(isset($_POST['submit_contact']))
If you are doing it from your local server, you will have to setup your mail properly in ini then only you will be able to send mail from your local machine.
A better approach would be to wrap the mail function in a statement. Mail is returning a bool value. And beginn as simple as possible.
error_reporting (E_ALL);
$to = "mail#whatever.com"
// ... your settings ...
if ( mail ( $to , $subject , $message ) ) {
// do when ok
}
else {
// do when error
}
To verify that you receive all values from $_POST do
echo '<pre>';
print_r ($_POST);
echo '</pre>';

Why is my php script not send the contact form to my email?

I tried creating a simple PHP script to send an email to me when someone fills out a contact form on my website but I get nan error that says:
inspirehealth.today is currently unable to handle this request.
HTTP ERROR 500
<?php
$first_name = $_POST('first_name');
$last_name = $_POST('last_name');
$email = $_POST('email');
$message = $_POST('message');
$to = "lewkowicz613#gmail.com";
$subject = "Message from Inspire Health";
mail ($to, $subject, $message, "From: " . $first_name . $last_name);
echo "Your Message Has Been Sent";
?>
and here is my html file relevant to the form
<section class="section-form js--contact" id="contact">
<div class="row">
<h3>Please Subscribe to Our Email List!</h3>
</div>
<div class="row">
<form method="post" action="form_process.php" class="contact-form">
<div class="row">
<div class="col span-1-of-3">
<label for="first_name">First Name</label>
</div>
<div class="col span-2-of-3">
<input type="text" name="first_name" id="first_name" placeholder="First Name" required>
</div>
</div>
<div class="row">
<div class="col span-1-of-3">
<label for="last_name">Last Name</label>
</div>
<div class="col span-2-of-3">
<input type="text" name="last_name" id="last_name" placeholder="Last name" required>
</div>
</div>
<div class="row">
<div class="col span-1-of-3">
<label for="email">Email</label>
</div>
<div class="col span-2-of-3">
<input type="email" name="email" id="email" placeholder="Your email" required>
</div>
</div>
<div class="row">
<div class="col span-1-of-3">
<label for="message">Drop us a line</label>
</div>
<div class="col span-2-of-3">
<textarea name="message" id="message" placeholder="Your message" ></textarea>
</div>
</div>
<div class="row">
<div class="col span-1-of-3">
<label> </label>
</div>
<div class="col span-2-of-3">
<input type="submit" value="Send it!">
</div>
</div>
</form>
</div>
</section>
Im not sure why its not working properly. Is it a server thing because I uploaded all the files to my domain root directory.
Thanks a lot.
$_POST is a global array, so try:
<?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "lewkowicz613#gmail.com";
$subject = "Message from Inspire Health";
mail ($to, $subject, $message, "From: " . $first_name . $last_name);
echo "Your Message Has Been Sent";
?>
Hope this helps :)

Web page contact form in PHP not working [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
So I have this HTML code for my contact form:
<section id="contact-form">
<form action="form.php" method="post" enctype="multipart/form-data">
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-12">
<div class="block">
<form>
<div class="form-group">
<input type="text" class="form-control" placeholder="Ime" name="name">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Email Adresa" name="email">
</div>
<div class="form-group">
<input type="text" class="form-control" name="subject" placeholder="Predmet">
</div>
</form>
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="block">
<form>
<div class="form-group-2">
<textarea class="form-control" rows="3" placeholder="Poruka" name="message"></textarea>
</div>
<button class="btn btn-default" type="submit">Pošalji</button>
</form>
</div>
</div>
</div>
</div>
</form>
</section>
And my PHP script looks like this:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: Kontakt s web-stranice';
$to = 'myEmailAddress';
$subject = 'Kontakt s web-stranice ';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
?>
<?php
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Thank you for your email!</p>';
} else {
echo '<p>Oops! An error occurred. Try sending your message again.</p>';
}
}
?>
And for some reason when I click on the submit button the web page refreshes and the message isn't sent to my email.
Does anyone know why?
Your HTML format is using forms within forms, so everything outside that <form> tag is not being collected. All you need to do is have the first <form> tag and wrap all your input boxes and the submit button in it.
Notice in the code below how you only need one <form>.
<section id="contact-form">
<form action="form.php" method="post" enctype="multipart/form-data">
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-12">
<div class="block">
<div class="form-group">
<input type="text" class="form-control" placeholder="Ime" name="name">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Email Adresa" name="email">
</div>
<div class="form-group">
<input type="text" class="form-control" name="subject" placeholder="Predmet">
</div>
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="block">
<div class="form-group-2">
<textarea class="form-control" rows="3" placeholder="Poruka" name="message"></textarea>
</div>
<button class="btn btn-default" type="submit">Pošalji</button>
</div>
</div>
</div>
</div>
</form>
</section>
Your PHP code is correct from the looks of things, but that messed up form tag was the big problem.

Categories