I am trying to send an email from a enquiry form available on a catalogue website on which I am working and found a strange issue.
On the same domain I have a file to test the email function with following code in it:
$sender = 'someone#somedomain.tld';
$recipient = 'name#gmail.com';
$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;
if (mail($recipient, $subject, $message, $headers))
{
echo "Message accepted";
}
else
{
echo "Error: Message not accepted";
}
and its working fine. But the same code is not working on the index.php page where I have the enquiry form and also not showing any error at all (I have checked the error log. I have also tried by putting this code in a separate file and by including it on index.php but the same result).
<form name="frm_enquiry" id="frm_enquiry" method="post" autocomplete="off">
<div class="row">
<div class="col-lg-3 col-md-3">
<div class="form-group">
<label for="fullname">Name:</label>
<input type="text" class="form-control" id="fullname" name="fullname" placeholder="Enter your name">
</div>
</div>
<div class="col-lg-3 col-md-3">
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter your email">
</div>
</div>
<div class="col-lg-3 col-md-3">
<div class="form-group">
<label for="mobile">Mobile No:</label>
<input type="text" class="form-control" id="mobile" name="mobile" placeholder="Enter your mobile number">
</div>
</div>
<div class="col-lg-3 col-md-3">
<div class="form-group">
<label style="width: 100%;" for="mobile"> </label>
<button type="submit" class="btn btn-block btn-primary" name="submit">Submit</button>
</div>
</div>
</div>
</form>
php:
if( isset( $_REQUEST['submit'] ) )
{
$name = $_REQUEST['fullname'];
$email = $_REQUEST['email'];
$mobile = $_REQUEST['mobile'];
echo $name . ' : ' . $email . ' : ' . $mobile . '<br>';
$sender = 'someone#somedomain.tld';
$recipient = 'name#gmail.com';
$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;
if (mail($recipient, $subject, $message, $headers))
{
echo "Message accepted";
}
}
Someone please guide me, what I am doing wrong here, I am stuck on this from last 2 days.
Thanks in advance.
Related
i am first time asking here, I don't know php coding ,i have one contact form on my webpage ,after filling which i get emails but twice in my inbox, I really don't know what changes should make in scripting here.i have added recptcha code here too by refering videos and docs but in php scripting there getting problem after submitting form
<?php
if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['tel']) && isset($_POST['loc']) && isset($_POST['message'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$loc = $_POST['loc'];
$message = $_POST['message'];
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Kindly provide valid Email Address.";
} else {
$body = $name . "\n" . $email . "\n" . $tel . "\n" . $loc . "\n" . $message;
if (mail('services#brickboys.com.au', 'Service Enquiry', $body, 'From:' . $email)) {
echo (mail('services#brickboys.com.au', 'Service Enquiry', $body, 'From:' . $email))."Thanks for contacting us.";
} else {
echo "<script>alert('Sorry!, there is a problem in sending email. Please call us on +61 452 534 200')</script>";
}
}
} else {
echo 'Message could not be sent.';
}
$curlx = curl_init();
curl_setopt($curlx, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
curl_setopt($curlx, CURLOPT_HEADER, 0);
curl_setopt($curlx, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlx, CURLOPT_POST, 1);
$post_data =
[
'secret' => '6LfRXOEhAAAAAOWyRGugvbPdYOhkztlz1aMcEwKP', //<--- your reCaptcha secret key
'response' => $_POST['g-recaptcha-response']
];
curl_setopt($curlx, CURLOPT_POSTFIELDS, $post_data);
$resp = json_decode(curl_exec($curlx));
curl_close($curlx);
if ($resp->success)
{
echo "<script>alert('Thanks For connecting us..we will get back to you soon..')</script>";
} else
{
// failed
echo "<script>alert('Please verify you are human..')</script>";
exit;
}
?>
<div class="col-md-6 padding-15">
<div class="contact-form">
<!-- https://brickboys.com.au/contact.php -->
<form action ="https://brickboys.com.au/contact.php"
method="post" id="ajax_form" class="form-horizontal">
<div class="form-group colum-row row">
<div class="col-sm-6">
<input type="text" id="name" name="name" class="form-control" placeholder="Name" required>
</div>
<div class="col-sm-6">
<input type="email" id="email" name="email" class="form-control" placeholder="Email" required>
</div>
</div>
<div class="form-group colum-row row">
<div class="col-sm-6">
<input type="tel" id="tel" name="tel" class="form-control" pattern="[0-9]{10}" placeholder="Phone 0452534200" required>
</div>
<div class="col-sm-6">
<input type="text" id="loc" name="loc" class="form-control" placeholder="Project Location">
</div>
</div>
<div class="form-group row">
<div class="col-md-12">
<textarea id="message" name="message" cols="30" rows="5" class="form-control message" placeholder="Message" required></textarea>
</div>
<div class="g-recaptcha col-sm-6 mt-2" data-sitekey="6LfRXOEhAAAAAJMek8MJn-kTKIzO-AKfg7JIp3zu"></div>
</div>
<div class="form-group row">
<div class="col-md-12">
<button id="submit" class="default-btn" type="submit">Send Message</button>
</div>
</div>
<div id="form-messages" class="alert" role="alert"></div>
</form>
</div>
</div>
</div>
</div>
</section>
if (mail('services#brickboys.com.au', 'Service Enquiry', $body, 'From:' . $email)) {
echo (mail('services#brickboys.com.au', 'Service Enquiry', $body, 'From:' . $email))."Thanks for contacting us.";
}
The problem in these lines you're calling mail() function within the if statement. You just need to echo your message there doesn't need to call the mail function again.
This is how you'll write your if statement.
if (mail('services#brickboys.com.au', 'Service Enquiry', $body, 'From:' . $email)) {
echo "Thanks for contacting us.";
}
I have a static site up (my portfolio site), with a form to send an email to me using a custom php.
the page is through github pages and the custom domain is through google.
the form is:
<div class="col-sm-12 col-md-6 wow fadeInUp" data-wow-duration="0.8s" data-wow-delay="0.2s">
<form id="contactForm" class="single-form quate-form wow fadeInUp" data-toggle="validator">
<div id="msgSubmit" class="h3 text-center hidden"></div>
<div class="row">
<div class="col-sm-12">
<input name="name" class="contact-name form-control" id="name" type="text" placeholder="First Name" required>
</div>
<div class="col-sm-12">
<input name="name" class="contact-email form-control" id="L_name" type="text" placeholder="Last Name" required>
</div>
<div class="col-sm-12">
<input name="name" class="contact-subject form-control" id="email" type="email" placeholder="Your Email" required>
</div>
<div class="col-sm-12">
<textarea class="contact-message" id="message" rows="6" placeholder="Your Message" required></textarea>
</div>
<!-- Subject Button -->
<div class="btn-form col-sm-12">
<button type="submit" class="btn btn-fill btn-block" id="form-submit">Send Message</button>
</div>
</div>
</form>
</div>
And the php to send it is:
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$EmailTo = "#gmail.com";
$Subject = "Portfolio CV/Resume";
// prepare email body text
$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:".$email);
// redirect to success page
if ($success){
echo "success";
}else{
echo "invalid";
}
?>
The actual error I get is:
POST https://codewithmarcus.com/process.php 405 jquery.min.js:4
I removed my actual email address from the code but rest assured it is in there correctly, any help would be appreciated.
405 http code means Not Allowed response status code indicates that the request method is known by the server but is not supported by the target resource.
And you won't be able to send email via Gmail through this script. To send email through Gmail, you need send it through SMPT server. You can use PHPmailer libraryfor that.
I am by no means a developer. Self-taught, but can usually wing it enough to make things happen. Working on company website for boss, and having trouble with the form. Regardless of how I try to define the PHP variable, SOME are not sending the input value to the e-mail. I'm sure I'm missing something simple, thank you in advance for your help! This is what's not showing:
Website:
Average Monthly Volume:
Preferred Contact Method:
Here is what I have so far:
HTML FORM:
<div class="product-screens2">
<div style="padding:200px">
<div class="form">
<div id="sendmessage">Your message has been sent. Thank you!</div>
<div id="errormessage">Please retry.</div>
<form action="form-email" method="post" role="form" class="contactForm">
<div class="form-row">
<div class="form-group col-lg-6">
<input type="text" name="name" class="form-control" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />
<div class="validation"></div>
</div>
<div class="form-group col-lg-6">
<input type="email" class="form-control" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" />
<div class="validation"></div>
</div>
<div class="form-group col-lg-6">
<input type="text" class="form-control" name="subject" id="subject" placeholder="Business Name" />
</div>
<div class="form-group col-lg-6">
<input type="text" name="name" class="form-control" id="business_site" placeholder="Business Website" />
</div>
<div class="form-group col-lg-6">
<input type="text" class="form-control" name="name" id="avgvolume" placeholder="Average Monthly Volume" />
</div>
<div class="form-group col-lg-6">
<input type="text" class="form-control" name="name" id="contactmethod" placeholder="Preferred Contact Method" />
</div>
</div>
<div class="form-group">
<textarea class="form-control" name="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Brief Description of Goods or Services Sold"></textarea>
<div class="validation"></div>
</div>
<div class="text-center"><button type="submit" title="Send Message">SUBMIT</button></div>
</form>
</div></div>
</div>
PHP MAILER SCRIPT
<?php
/***************** Configuration *****************/
// Enter your email, where you want to receive the messages.
$contact_email_to = "Support#XXXXX.com";
// Subject prefix
$contact_subject_prefix = "Message From XXXXX Website: ";
// Name too short error text
$contact_error_name = "Name is too short or empty!";
// Email invalid error text
$contact_error_email = "Please enter a valid email!";
// Subject too short error text
$contact_error_subject = "Subject is too short or empty!";
// Message too short error text
$contact_error_message = "Too short message! Please enter something.";
/********** Do not edit from the below line ***********/
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
die('Sorry Request must be Ajax POST');
}
if(isset($_POST)) {
$name = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
$email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
$subject = filter_var($_POST["subject"], FILTER_SANITIZE_STRING);
$message = filter_var($_POST["message"], FILTER_SANITIZE_STRING);
$business_site = $_POST["business_site"];
$avgvolume = $_POST["avgvolume"];
$contactmethod = $_POST["contactmethod"];
if(strlen($name)<4){
die($contact_error_name);
}
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
die($contact_error_email);
}
if(strlen($message)<3){
die($contact_error_subject);
}
if(strlen($message)<3){
die($contact_error_message);
}
if(!isset($contact_email_from)) {
$contact_email_from = "contactform#" . #preg_replace('/^www\./','', $_SERVER['SERVER_NAME']);
}
$sendemail = mail($contact_email_to, $contact_subject_prefix . $subject,
"Name: $name" . PHP_EOL .
"Reply-To: $email" . PHP_EOL .
"Business: $subject" . PHP_EOL .
"Website: $business_site" . PHP_EOL .
"Average Monthly Volume: $avgvolume" . PHP_EOL .
"Preferred Contact Method: $contactmethod" . PHP_EOL .
"Business Description: $message" . PHP_EOL .
"X-Mailer: PHP/" . phpversion()
);
if( $sendemail ) {
echo 'OK';
} else {
echo 'Could not send mail! Please check your PHP mail configuration.';
}
}
?>
When I try to click sent button, the content from the webpage is not redirecting to the .php page.I am using recaptcha in the form .Can you please help me to solve this issue..
my HTML code is:
<form action="sendform.php" id="contact-form" class="form-horizontal"
method="post">
<fieldset>
<div class="form-group">
<label class="col-sm-4 control-label" for="name">Your Name</label>
<div class="col-sm-8">
<input type="text" placeholder="Your Name" class="form-control" name="name" id="name">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label" for="email">Email Address</label>
<div class="col-sm-8">
<input type="text" placeholder="Enter Your Email Address" class="form-control" name="email" id="email">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label" for="subject">Subject</label>
<div class="col-sm-8">
<input type="text" placeholder="Subject" class="form-control" name="subject" id="subject" list="exampleList">
<datalist id="exampleList" >
<option value="a">A</option>
<option value="b">B Combo</option>
</datalist>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label" for="message">Your Message</label>
<div class="col-sm-8">
<textarea placeholder="Please Type Your Message" class="form-control" name="message" id="message" rows="3"></textarea>
</div>
</div>
<div class="col-sm-8" class="form-group" class="g-recaptcha" data-sitekey="xxxxxxyyyyyyy"></div>
<div class="col-sm-offset-4 col-sm-8">
<button type="submit" value="Send" id="submit" name="submit" class="submit_btn float_l">Submit</button>
<button type="reset" class="btn btn-primary">Cancel</button>
</div>
</fieldset>
</form>
And my PHP Code sendform.php
<?php
if (isset($_POST['submit']) && !empty($_POST['submit'])):
if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):
//your site secret key
$secret = 'xxxxxxxxxxxxx';
//get verify response data
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secret . '&response=' . $_POST['g-recaptcha-response']);
$responseData = json_decode($verifyResponse);
if ($responseData->success):
$to = "aaa#abc.com"; // this is your Email address
$from = !empty($_POST['email']) ? $_POST['email'] : ''; // this is the sender's Email address
$name = !empty($_POST['name']) ? $_POST['name'] : '';
$subject = !empty($_POST['subject']) ? $_POST['subject'] : '';
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers = "From:" . $from;
$headers .= 'From:' . $name . ' <' . $from . '>' . "\r\n";
$headers2 = "From:" . $to;
mail($to, $subject, $message, $headers);
$succMsg = 'Your request have submitted successfully.';
else:
$errMsg = 'Robot verification failed, please try again.';
endif;
else:
$errMsg = 'Please click on the reCAPTCHA box.';
endif;
else:
$errMsg = '';
$succMsg = '';
endif;
?>
I have tested your code and it works.
Please make sure that you have placed your html and php files in same directory and also your files should be served via a local running server.
So your url should look like this http://localhost/testing/index.html
Although, your sendform.php gives me captcha error ofcourse.
"Please click on the reCAPTCHA box."
Hey guys so I have an HTML document with a contact form I created and it is not working. I have the PHP in a seperate PHP file like so:
HTML:
<form class="form-horizontal" action="form_process.php" method="post" name="contact_form">
<div class="form-group">
<label class="col-sm-2 control-label white-color">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" name="email" placeholder="Email" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label white-color">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="name" placeholder="First Name" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label white-color">Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="5" placeholder="Type your message here!" name="message" required></textarea>
<button type="submit" class="btn btn-default btn-lg text-center" id="send-btn" name="submit">Send</button>
</div>
</div>
</form>
And here is the PHP:
<?php
if (isset($POST['name']) && isset($_POST['email'])) {
$email = $_POST['email'];
$name = $_POST['name'];
$message = $_POST['message'];
$to = 'j_goris#live.com';
$subject = 'JorgeGoris.com Form Submission';
$text = "Name: ".$name."\n"."Email: ".$email."\n". "Wrote the following: "."\n\n".$message;
if(mail($to, $subject, $text, "From: ".$name)){
echo '<h1>Thanks! I will get back to you shortly.</h1>';
}
else {
echo 'Sorry there was an error! Please try again.';
}
}?>
This is my first time tackling PHP contact forms. I uploaded all my files to my server and still no dice. Can you guys see whats wrong?
Replace:
$POST['name']
to:
$_POST['name']
Replace:
if(mail($to, $subject, $text, "From: ".$name)){
To:
if(mail($to, $subject, $text, "From: ".$email)){
Full Code:
<?php
if (isset($_POST['name']) && isset($_POST['email'])) {
$email = $_POST['email'];
$name = $_POST['name'];
$message = $_POST['message'];
$to = 'j_goris#live.com';
$subject = 'JorgeGoris.com Form Submission';
$text = "Name: ".$name."\n"."Email: ".$email."\n". "Wrote the following: "."\n\n".$message;
if(mail($to, $subject, $text, "From: ".$email)){
echo '<h1>Thanks! I will get back to you shortly.</h1>';
}
else {
echo 'Sorry there was an error! Please try again.';
}
}
?>