Topic: What's wrong with this PHP code?

Why is the PHP code below not inserting into my database and sending me an email even after I have inserted the right details?


$errors = '';
$myemail = '';//<-----Put Your email address here.
if(empty($_POST['yourname'])  || 
   empty($_POST['email_address']) ||
   empty($_POST['Message']) || 
    $errors .= "\n Error: all fields are required";
    echo '<br>' . $errors . '<br>';

$yourname = $_POST['yourname']; 
$email_address = $_POST['email_address']; 
$Message = $_POST['Message'];
$captcha = $_POST['captcha']; 

if (!preg_match(
    $errors .= "\n Error: Invalid email address";
    echo '<br>' . $errors . '<br>';

if ( $captcha != 2)
   $errors .= "\n You inserted the wrong number of <b>FULL</b> bananas. You are not a genuine person!";
   echo '<br>' . $errors . '<br>';

if( empty($errors))


// Include database connection settings

$yourname = $_POST['yourname']; 
$email_address = $_POST['email_address']; 
$Message = $_POST['Message']; 

mysql_query("INSERT INTO `thuitam_myDatabase`.`Contact_info` (
`Index` ,
`Name` ,
`Email Address` ,
NULL, '$yourname', '$email_address','$Message')

//close connection                          

$to = $myemail;

$email_subject = "Contact form submission: $yourname";

$email_body = "You have received a new message. ".

" Here are the details:\n Name: $yourname \n ".

"Email: $email_address\n Message \n $Message";

$headers = "From: $myemail\n";

$headers .= "Reply-To: $email_address";


//Say 'thank you'
//echo '<br>' . $errors . '<br>';
echo '<p>Hi' . $yourname . '!</p>

<p>Thank you for contacting me. I will try my best to get back to you as soon as possible. In case I delay in responding, feel free to call me via phone. My number is +254725-509941.</p>

<p>Wishing You Every Joy,</p>

<p>Thuita J. Maina.</>



NOTE: I am using lightboxes for the form from which data to be manipulated by PHP code is coming from.
Below is the form from which data to be manipulated by the PHP code is coming from:

<form  action="contact_response.php" method="post" target="_parent"> 
    <p>Your Name: <br>
      <input type="text" name="yourname"  id="yourname" maxlength="100" size="40" 
    <p>Email address: <br> 
      <input type="text" name="email_address" id="email_address" maxlength="100" size="40">
    <p> Message: <br>
       <textarea name="Message" rows="10" cols="40"></textarea>
   <label for='captcha'> Just to ensure you are a genuine person, please tell me how many <b>FULL</b> bananas you can see in the image 
   <input type="text" name="captcha" id="captcha"  maxlength="100" /><br>
   <img src="/images/captcha.jpg" style="width:300px"><br>
      <!--<button onClick="openbox('Invalid Data', 1)">Submit</button>-->
      <!--<button onClick="openbox('Response', 1)">Submit</button>-->
      <?php include 'contact_response.php'; ?><input type="submit" value="Submit" onClick="openbox('Response', 1)" target="_parent">
      <input type="button" name="cancel" value="Cancel" onClick="closebox()">

Re: What's wrong with this PHP code?

A security feature aimed at keeping our servers off various spam blacklists is currently enabled. All outgoing emails will need to specify correct mail headers and avoid any types of spoofing. If you are using a PHP mailing script - please either do not set any FROM header, or if you need to set one - please specify a return address (FROM header) that corresponds with your domain name.
Basically, all you need to do is ensure that you authenticate with the same email account login details that you are using to send the mail from.

Re: What's wrong with this PHP code?

No error in your code, check once again in your mail server.

Re: What's wrong with this PHP code?

code looks fine. need to check mail server.

Re: What's wrong with this PHP code?

Mahisha wrote:

No error in your cdg paris transfer code, check once again in your mail server.

For me too bug that times and I do not know if it's just connected to the connection that sometimes is a bit slow!