-1

I am trying to send email by on click submit button of a form but after submitting the given form the message appear as "Your mail has been sent successfully ! Thank you for your feedback" but actually the email isn't sent to a given email id entered by user in a form...please help me to solve the given issue!!!

//secure_email_form.php
<body>

<div class="container">
<!-- Feedback Form Starts Here -->
<div id="feedback">
<!-- Heading Of The Form -->
<div class="head">
<h3>FeedBack Form</h3>
<p>This is feedback form. Send us your feedback !</p>
</div>
<!-- Feedback Form -->
<form action="#" id="form" method="post" name="form">
<input name="vname" placeholder="Your Name" type="text" value="">
<input name="vemail" placeholder="Your Email" type="text" value="">
<input name="sub" placeholder="Subject" type="text" value="">
<label>Your Suggestion/Feedback</label>
<textarea name="msg" placeholder="Type your text here..."></textarea>
<input id="send" name="submit" type="submit" value="Send Feedback">
</form>
<h3><?php include "secure_email_code.php"?></h3>
</div>
<!-- Feedback Form Ends Here -->
</div>
</body>

//secure_email_code.php
<?php
if(isset($_POST["submit"])){
// Checking For Blank Fields..
if($_POST["vname"]==""||$_POST["vemail"]==""||$_POST["sub"]==""||$_POST["msg"]==""){
echo "Fill All Fields..";
}else{
// Check if the "Sender's Email" input field is filled out
$email=$_POST['vemail'];
// Sanitize E-mail Address
$email =filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate E-mail Address
$email= filter_var($email, FILTER_VALIDATE_EMAIL);
if (!$email){
echo "Invalid Sender's Email";
}
else{
$subject = $_POST['sub'];
$message = $_POST['msg'];
$headers = 'From:'.'info@example.com'."\r\n"; // Sender's Email
$headers = 'Cc:'.'info@example1.com'."\r\n"; // Carbon copy to Sender
// Message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70);
// Send Mail By PHP Mail Function
mail("recievers_mail_id@xyz.com", $subject, $message, $headers);
echo "Your mail has been sent successfuly ! Thank you for your feedback";
}
}
}
?>
Rkboss
  • 19
  • 6

2 Answers2

1

Looks like your mail function isn't executing properly. You can try debugging using var_dump or something.

Also, your code is logically incorrect. It should show the message only when the mail function executes successfully.

$send_mail = mail("recievers_mail_id@xyz.com", $subject, $message, $headers);
var_dump($send_mail);  // See what you get here. It'll probably show false.

if ($send_mail) {
   echo "Your mail has been sent successfuly ! Thank you for your feedback";
} else {
    echo "Email sending failed!";
}
Indrasis Datta
  • 8,692
  • 2
  • 14
  • 32
  • i edited my code, it shows "bool(false) Email sending failed!" error. – Rkboss Jul 18 '16 at 06:26
  • Unfortunately, the mail function isn't configured enough to show you the appropriate error message. It returns only true and false. If you want a more reliable way, you should be using PHP Mailer. – Indrasis Datta Jul 18 '16 at 06:28
0

You have to use a php file url or use blank in action. Here you have to use action blank.

<form action="" id="form" method="post" name="form"> 

instead

<form action="#" id="form" method="post" name="form">
Bubai Das
  • 58
  • 9