Jump to content

PHP Form Mailer + Securimage


chromeq

Recommended Posts

Hello all! First post.

 

Wondering if anyone could help me out with a problem I've been having with a form mailer...

I had it working at one point in time, but now not so much.

I'm using Securimage as a captcha

The file is email.php

 

My problem is... When you type in the code wrong, it tells you its wrong.  When you type the code right, it redirects to thank.html, which is correct...but never sends the mail!  Am I missing something obvious?

 

 

Here's my code:

 

 

<?php 
session_start();



//include_once $_SERVER['DOCUMENT_ROOT'] . '/coaxicom_email_original/securimage/securimage.php';
include_once('securimage/securimage.php');
$securimage = new Securimage();



if( isset($_POST['submit'])) {

if ($securimage->check($_POST['captcha_code']) == false) {
  // the code was incorrect
  // you should handle the error so that the form processor doesn't continue

  // or you can use the following code if there is no validation or you do not know how
  echo "The security code entered was incorrect.<br /><br />";
  echo "<a href='email.php'>Please click this link to back and try again.</a>";
  exit;
}


//Data
$contact1 = $_POST['contact1'];
$company1 = $_POST['company1'];
$email1 = $_POST['email1'];
$phone1 = $_POST['phone1'];
$country1 = $_Post['country1'];
$address1 = $_POST['address1'];
$city1 = $_POST['city1'];
$state1 = $_POST['state1'];
$zip1 = $_POST['zip1'];
$contact2 = $_POST['contact2'];
$company2 = $_POST['company2'];
$email2 = $_POST['email2'];
$phone2 = $_POST['phone2'];
$country2 = $_Post['country2'];
$address2 = $_POST['address2'];
$city2 = $_POST['city2'];
$state2 = $_POST['state2'];
$zip2 = $_POST['zip2'];
$contact3 = $_POST['contact3'];
$company3 = $_POST['company3'];
$email3 = $_POST['email3'];
$phone3 = $_POST['phone3'];
$country3 = $_Post['country3'];
$address3 = $_POST['address3'];
$city3 = $_POST['city3'];
$state3 = $_POST['state3'];
$zip3 = $_POST['zip3'];
$contact4 = $_POST['contact4'];
$company4 = $_POST['company4'];
$email4 = $_POST['email4'];
$phone4 = $_POST['phone4'];
$country4 = $_Post['country4'];
$address4 = $_POST['address4'];
$city4 = $_POST['city4'];
$state4 = $_POST['state4'];
$zip4 = $_POST['zip4'];
$contact5 = $_POST['contact5'];
$company5 = $_POST['company5'];
$email5 = $_POST['email5'];
$phone5 = $_POST['phone5'];
$country5 = $_Post['country5'];
$address5 = $_POST['address5'];
$city5 = $_POST['city5'];
$state5 = $_POST['state5'];
$zip5 = $_POST['zip5'];
$contact6 = $_POST['contact6'];
$company6 = $_POST['company6'];
$email6 = $_POST['email6'];
$phone6 = $_POST['phone6'];
$country6 = $_Post['country6'];
$address6 = $_POST['address6'];
$city6 = $_POST['city6'];
$state6 = $_POST['state6'];
$zip6 = $_POST['zip6'];
$contact7 = $_POST['contact7'];
$company7 = $_POST['company7'];
$email7 = $_POST['email7'];
$phone7 = $_POST['phone7'];
$country7 = $_Post['country7'];
$address7 = $_POST['address7'];
$city7 = $_POST['city7'];
$state7 = $_POST['state7'];
$zip7 = $_POST['zip7'];
$contact8 = $_POST['contact8'];
$company8 = $_POST['company8'];
$email8 = $_POST['email8'];
$phone8 = $_POST['phone8'];
$country8 = $_Post['country8'];
$address8 = $_POST['address8'];
$city8 = $_POST['city8'];
$state8 = $_POST['state8'];
$zip8 = $_POST['zip8'];



$body = <<<EOD
<br /><hr><br />
Company: $company1 <br />
Contact: $contact1 <br />
Email: $email1 <br />
Phone: $phone1 <br />
Country: $country1 <br />
Address: $address1 <br />
City: $city1 <br />
State: $state1 <br />
Zip: $zip1 <br />
<br /><hr><br />
Company: $company2 <br />
Contact: $contact2 <br />
Email: $email2 <br />
Phone: $phone2 <br />
Country: $country2 <br />
Address: $address2 <br />
City: $city2 <br />
State: $state2 <br />
Zip: $zip2 <br />
<br /><hr><br />
Company: $company3 <br />
Contact: $contact3 <br />
Email: $email3 <br />
Phone: $phone3 <br />
Country: $country3 <br />
Address: $address3 <br />
City: $city3 <br />
State: $state3 <br />
Zip: $zip3 <br />
<br /><hr><br />
Company: $company4 <br />
Contact: $contact4 <br />
Email: $email4 <br />
Phone: $phone4 <br />
Country: $country4 <br />
Address: $address4 <br />
City: $city4 <br />
State: $state4 <br />
Zip: $zip4 <br />
<br /><hr><br />
Company: $company5 <br />
Contact: $contact5 <br />
Email: $email5 <br />
Phone: $phone5 <br />
Country: $country5 <br />
Address: $address5 <br />
City: $city5 <br />
State: $state5 <br />
Zip: $zip5 <br />
<br /><hr><br />
Company: $company6 <br />
Contact: $contact6 <br />
Email: $email6 <br />
Phone: $phone6 <br />
Country: $country6 <br />
Address: $address6 <br />
City: $city6 <br />
State: $state6 <br />
Zip: $zip6 <br />
<br /><hr><br />
Company: $company7 <br />
Contact: $contact7 <br />
Email: $email7 <br />
Phone: $phone7 <br />
Country: $country7 <br />
Address: $address7 <br />
City: $city7 <br />
State: $state7 <br />
Zip: $zip7 <br />
<br /><hr><br />
Company: $company8 <br />
Contact: $contact8 <br />
Email: $email8 <br />
Phone: $phone8 <br />
Country: $country8 <br />
Address: $address8 <br />
City: $city8 <br />
State: $state8 <br />
Zip: $zip8 <br />
<br /><hr><br />
EOD;






//Subject and Email
$emailSubject = 'This is my subject';
$webMaster = 'example@gmail.com';
$headers = "From: Example\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster,$emailSubject,$body,$headers);
header( "Location: thank.html" );



} 
else {
?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>

<div id="wrapper">
<div id="main">



<div id="fContainer">

<form action="email.php" 
  method="post" >



<div class="fbox" id="f1">
<div class="fLine"><div class="fLabel">Company Name:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="company1" /></div></div> <br />
<div class="fLine"><div class="fLabel">Contact:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="contact1" /></div></div> <br />
<div class="fLine"><div class="fLabel">E-mail:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="email1" /></div></div> <br />
<div class="fLine"><div class="fLabel">Phone:</div>
<div class="fInput"><input type="text" size="15" maxlength="50" name="phone1" /></div></div> <br />
<div class="fLine"><div class="fLabel">Country:</div>
<div class="fInput"><input type="text" size="20" maxlength="300" name="country1" /></div></div> <br />
<div class="fLine"><div class="fLabel">Address:</div>
<div class="fInput"><input type="text" size="20" maxlength="300" name="address1" /></div></div> <br />
<div class="fLine"><div class="fLabel">City:</div>
<div class="fInput"><input type="text" size="18" maxlength="100" name="city1" /></div></div> <br />
<div class="fLine"><div class="fLabel">State:</div>
<div class="fInput"><input type="text" size="10" maxlength="100" name="state1" /></div></div> <br />
<!-- end #f1 --></div>
<div class="fbox" id="f2">
<div class="fLine"><div class="fLabel">Company Name:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="company2" /></div></div> <br />
<div class="fLine"><div class="fLabel">Contact:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="contact2" /></div></div> <br />
<div class="fLine"><div class="fLabel">E-mail:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="email2" /></div></div> <br />
<div class="fLine"><div class="fLabel">Phone:</div>
<div class="fInput"><input type="text" size="15" maxlength="50" name="phone2" /></div></div> <br />
<div class="fLine"><div class="fLabel">Country:</div>
<div class="fInput"><input type="text" size="20" maxlength="300" name="country2" /></div></div> <br />
<div class="fLine"><div class="fLabel">Address:</div>
<div class="fInput"><input type="text" size="20" maxlength="300" name="address2" /></div></div> <br />
<div class="fLine"><div class="fLabel">City:</div>
<div class="fInput"><input type="text" size="18" maxlength="100" name="city2" /></div></div> <br />
<div class="fLine"><div class="fLabel">State:</div>
<div class="fInput"><input type="text" size="10" maxlength="100" name="state2" /></div></div> <br />
<!-- end #f2 --></div>
<div class="fbox" id="f3">
<div class="fLine"><div class="fLabel">Company Name:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="company3" /></div></div> <br />
<div class="fLine"><div class="fLabel">Contact:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="contact3" /></div></div> <br />
<div class="fLine"><div class="fLabel">E-mail:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="email3" /></div></div> <br />
<div class="fLine"><div class="fLabel">Phone:</div>
<div class="fInput"><input type="text" size="15" maxlength="50" name="phone3" /></div></div> <br />
<div class="fLine"><div class="fLabel">Country:</div>
<div class="fInput"><input type="text" size="20" maxlength="300" name="country3" /></div></div> <br />
<div class="fLine"><div class="fLabel">Address:</div>
<div class="fInput"><input type="text" size="20" maxlength="300" name="address3" /></div></div> <br />
<div class="fLine"><div class="fLabel">City:</div>
<div class="fInput"><input type="text" size="18" maxlength="100" name="city3" /></div></div> <br />
<div class="fLine"><div class="fLabel">State:</div>
<div class="fInput"><input type="text" size="10" maxlength="100" name="state3" /></div></div> <br />
<!-- end #f3 --></div>
<div class="fbox" id="f4">
<div class="fLine"><div class="fLabel">Company Name:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="company4" /></div></div> <br />
<div class="fLine"><div class="fLabel">Contact:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="contact4" /></div></div> <br />
<div class="fLine"><div class="fLabel">E-mail:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="email4" /></div></div> <br />
<div class="fLine"><div class="fLabel">Phone:</div>
<div class="fInput"><input type="text" size="15" maxlength="50" name="phone4" /></div></div> <br />
<div class="fLine"><div class="fLabel">Country:</div>
<div class="fInput"><input type="text" size="20" maxlength="300" name="country4" /></div></div> <br />
<div class="fLine"><div class="fLabel">Address:</div>
<div class="fInput"><input type="text" size="20" maxlength="300" name="address4" /></div></div> <br />
<div class="fLine"><div class="fLabel">City:</div>
<div class="fInput"><input type="text" size="18" maxlength="100" name="city4" /></div></div> <br />
<div class="fLine"><div class="fLabel">State:</div>
<div class="fInput"><input type="text" size="10" maxlength="100" name="state4" /></div></div> <br />
<!-- end #f4 --></div>
<div class="fbox" id="f5">
<div class="fLine"><div class="fLabel">Company Name:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="company5" /></div></div> <br />
<div class="fLine"><div class="fLabel">Contact:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="contact5" /></div></div> <br />
<div class="fLine"><div class="fLabel">E-mail:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="email5" /></div></div> <br />
<div class="fLine"><div class="fLabel">Phone:</div>
<div class="fInput"><input type="text" size="15" maxlength="50" name="phone5" /></div></div> <br />
<div class="fLine"><div class="fLabel">Country:</div>
<div class="fInput"><input type="text" size="20" maxlength="300" name="country5" /></div></div> <br />
<div class="fLine"><div class="fLabel">Address:</div>
<div class="fInput"><input type="text" size="20" maxlength="300" name="address5" /></div></div> <br />
<div class="fLine"><div class="fLabel">City:</div>
<div class="fInput"><input type="text" size="18" maxlength="100" name="city5" /></div></div> <br />
<div class="fLine"><div class="fLabel">State:</div>
<div class="fInput"><input type="text" size="10" maxlength="100" name="state5" /></div></div> <br />
<!-- end #f5 --></div>
<div class="fbox" id="f6">
<div class="fLine"><div class="fLabel">Company Name:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="company6" /></div></div> <br />
<div class="fLine"><div class="fLabel">Contact:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="contact6" /></div></div> <br />
<div class="fLine"><div class="fLabel">E-mail:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="email6" /></div></div> <br />
<div class="fLine"><div class="fLabel">Phone:</div>
<div class="fInput"><input type="text" size="15" maxlength="50" name="phone6" /></div></div> <br />
<div class="fLine"><div class="fLabel">Country:</div>
<div class="fInput"><input type="text" size="20" maxlength="300" name="country6" /></div></div> <br />
<div class="fLine"><div class="fLabel">Address:</div>
<div class="fInput"><input type="text" size="20" maxlength="300" name="address6" /></div></div> <br />
<div class="fLine"><div class="fLabel">City:</div>
<div class="fInput"><input type="text" size="18" maxlength="100" name="city6" /></div></div> <br />
<div class="fLine"><div class="fLabel">State:</div>
<div class="fInput"><input type="text" size="10" maxlength="100" name="state6" /></div></div> <br />
<!-- end #f6 --></div>
<div class="fbox" id="f7">
<div class="fLine"><div class="fLabel">Company Name:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="company7" /></div></div> <br />
<div class="fLine"><div class="fLabel">Contact:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="contact7" /></div></div> <br />
<div class="fLine"><div class="fLabel">E-mail:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="email7" /></div></div> <br />
<div class="fLine"><div class="fLabel">Phone:</div>
<div class="fInput"><input type="text" size="15" maxlength="50" name="phone7" /></div></div> <br />
<div class="fLine"><div class="fLabel">Country:</div>
<div class="fInput"><input type="text" size="20" maxlength="300" name="country7" /></div></div> <br />
<div class="fLine"><div class="fLabel">Address:</div>
<div class="fInput"><input type="text" size="20" maxlength="300" name="address7" /></div></div> <br />
<div class="fLine"><div class="fLabel">City:</div>
<div class="fInput"><input type="text" size="18" maxlength="100" name="city7" /></div></div> <br />
<div class="fLine"><div class="fLabel">State:</div>
<div class="fInput"><input type="text" size="10" maxlength="100" name="state7" /></div></div> <br />
<!-- end #f7 --></div>
<div class="fbox" id="f8">
<div class="fLine"><div class="fLabel">Company Name:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="company8" /></div></div> <br />
<div class="fLine"><div class="fLabel">Contact:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="contact8" /></div></div> <br />
<div class="fLine"><div class="fLabel">E-mail:</div>
<div class="fInput"><input type="text" size="25" maxlength="150" name="email8" /></div></div> <br />
<div class="fLine"><div class="fLabel">Phone:</div>
<div class="fInput"><input type="text" size="15" maxlength="50" name="phone8" /></div></div> <br />
<div class="fLine"><div class="fLabel">Country:</div>
<div class="fInput"><input type="text" size="20" maxlength="300" name="country8" /></div></div> <br />
<div class="fLine"><div class="fLabel">Address:</div>
<div class="fInput"><input type="text" size="20" maxlength="300" name="address8" /></div></div> <br />
<div class="fLine"><div class="fLabel">City:</div>
<div class="fInput"><input type="text" size="18" maxlength="100" name="city8" /></div></div> <br />
<div class="fLine"><div class="fLabel">State:</div>
<div class="fInput"><input type="text" size="10" maxlength="100" name="state8" /></div></div> <br />
<!-- end #f8 --></div>









<div id="fCaptcha">
<div id="codeLabel">Security Code<span class="red">*</span>:</div>
<div id="img"><img id="captcha" src="securimage/securimage_show.php" alt="CAPTCHA Image" /></div>
<div id="text">
<input type="text" name="captcha_code" size="10" maxlength="6" /></div>
<!-- end #fCaptcha --></div>
<div id="fCaptchaBox"></div>
<div id="fSubmit"><input type="submit" name="submit" value="Email This Form" /></div>
</form>
<!-- end #fContainer --></div>




<!-- end #main --></div>
<!-- end #wrapper --></div>





</body>
</html>





<?php
}
?>

Link to comment
Share on other sites

What I do often is to look at the page source. I save this as abc.htm and then run that on its own rather than the php file. It quite often helps me debug stuff. You may find it will help. I suspect it is an issue between what is going on before the page gets presented as html and after the page is displayed in the browser because the form submit will load up the thankyou page..

 

If that does not help, then comment out everything but the bare essentials and run that on its own. This may help you see where the problem is.

Cheers

Link to comment
Share on other sites

Thanks for the help so far.

Put the error check in and noticed that I had variables in my php that were missing in my html...however

Mail function still does not work.  No errors show up though.

 

Securimage is showing up correctly with the captcha.  When I send out the form it tells me if the code was correct or incorrect.  It sends me to the thank.html page, but never sends the email.

 

I forget the example where I got the idea of how to make this, but this is the flow...

Overall, check to see if form is submitted, if not, show the html

if form is submitted, check if securimage is correct

if securimage is false, exit.  else, continue with data until you are redirected to thank.html

 

Is the way I wrapped the html in the "else" statement for "if the form is submitted" wrong?

 

 

I've taken the following code and put it as simply as I can

<?php 
session_start();
error_reporting(E_ALL);


include_once('securimage/securimage.php');
$securimage = new Securimage();



if( isset($_POST['submit'])) {

if ($securimage->check($_POST['captcha_code']) == false) {
  // the code was incorrect
  echo "The security code entered was incorrect.<br /><br />";
  echo "<a href='email.php'>Please click this link to back and try again.</a>";
  exit;
}


else {
//Data
$contact1 = $_POST['contact1'];
$company1 = $_POST['company1'];
$email1 = $_POST['email1'];
$phone1 = $_POST['phone1'];
$country1 = $_POST['country1'];
$address1 = $_POST['address1'];
$city1 = $_POST['city1'];
$state1 = $_POST['state1'];
$zip1 = $_POST['zip1'];	


$body = <<<EOD
<br /><hr><br />
Company: $company1 <br />
Contact: $contact1 <br />
Email: $email1 <br />
Phone: $phone1 <br />
Country: $country1 <br />
Address: $address1 <br />
City: $city1 <br />
State: $state1 <br />
Zip: $zip1 <br />
EOD;






//Subject and Email

$emailSubject = 'This is the email subject';
$webMaster = 'example@gmail.com';


$headers = "From: noreply@example.net\r\n";
$headers .= "Content-type: text/html\r\n";

$success = mail($webMaster,$emailSubject,$body,$headers);


header( "Location: thank.html" );

//end if securimage is NOT FALSE
}

//end if submitted
} 

//if not submitted yet
else {


?>

<html>
</html>

<?php
}
?>

Link to comment
Share on other sites

Hey, sorry, wouldn't let me edit...

 

Maybe the problem is the

$success = mail($webMaster,$emailSubject,$body,$headers);

 

changing this to just

mail($webMaster,$emailSubject,$body,$headers);

still doesn't send the email, but maybe this has something to do with my problem?

 

Link to comment
Share on other sites

You have to get used to the idea of breaking down your program into Mickey-Mouse simple snippits which hold the problem. Test those on their own, and then re-construct with the correct code. So, for example, write a program with just the mail statement part and find out if that is failing. Get that working, then insert it into the other part which IS working and voila! a working program.

 

hope that helps

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.