Help required with PHP Please

User 2744602 Photo


Registered User
162 posts

Hi all :)
Sorry I do not know anything about .php but I have been following some instructions and did have the mail processor working outside of RSD on the below host and working fine with no issues..

Once again this site is being constructed for my Cert IV in IT :) and as I had to do something a bit more complicated I thought I may as well make something I will get some knowledge out of!

Site is located here: brettburgess.tk/test_centre/

Now when I use the form on the site I do not get any errors and in fact it goes to the Success page "success.html" however you will not see that page as yet.

It should only be something simple, but I can not see it :( Any help or advice to a tutorial would be great please :)

The processor:

<?php
function ValidateEmail($email)
{
$pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i';
return preg_match($pattern, $email);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['formid'] == 'processorform1')
{
$mailto = 'myemail@hotmail.com';
$mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;
$subject = 'TESTING';
$message = 'Values submitted from web site form:';
$success_url = './contact/success.html';
$error_url = './contact/fail.html';
$error = '';
$eol = "\n";
$max_filesize = isset($_POST['filesize']) ? $_POST['filesize'] * 1024 : 1024000;
$boundary = md5(uniqid(time()));

$header = 'From: '.$mailfrom.$eol;
$header .= 'Reply-To: '.$mailfrom.$eol;
$header .= 'MIME-Version: 1.0'.$eol;
$header .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'.$eol;
$header .= 'X-Mailer: PHP v'.phpversion().$eol;
if (!ValidateEmail($mailfrom))
{
$error .= "The specified email address is invalid!\n<br>";
}

if (!empty($error))
{
$errorcode = file_get_contents($error_url);
$replace = "##error##";
$errorcode = str_replace($replace, $error, $errorcode);
echo $errorcode;
exit;
}

$internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha_code", "recaptcha_challenge_field", "recaptcha_response_field", "g-recaptcha-response");
$message .= $eol;
$message .= "IP Address : ";
$message .= $_SERVER['REMOTE_ADDR'];
$message .= $eol;
foreach ($_POST as $key => $value)
{
if (!in_array(strtolower($key), $internalfields))
{
if (!is_array($value))
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol;
}
else
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol;
}
}
}
$body = 'This is a multi-part message in MIME format.'.$eol.$eol;
$body .= '--'.$boundary.$eol;
$body .= 'Content-Type: text/plain; charset=ISO-8859-1'.$eol;
$body .= 'Content-Transfer-Encoding: 8bit'.$eol;
$body .= $eol.stripslashes($message).$eol;
if (!empty($_FILES))
{
foreach ($_FILES as $key => $value)
{
if ($_FILES[$key]['error'] == 0 && $_FILES[$key]['size'] <= $max_filesize)
{
$body .= '--'.$boundary.$eol;
$body .= 'Content-Type: '.$_FILES[$key]['type'].'; name='.$_FILES[$key]['name'].$eol;
$body .= 'Content-Transfer-Encoding: base64'.$eol;
$body .= 'Content-Disposition: attachment; filename='.$_FILES[$key]['name'].$eol;
$body .= $eol.chunk_split(base64_encode(file_get_contents($_FILES[$key]['tmp_name']))).$eol;
}
}
}
$body .= '--'.$boundary.'--'.$eol;
if ($mailto != '')
{
mail($mailto, $subject, $body, $header);
}
header('Location: '.$success_url);
exit;
}
?>


The HTML

<div class="coffee-span-12">

<form class="form-container form-container-1" name="contact" method="post" action="processor.php" enctype="multipart/form-data" id="indexForm1" onsubmit="return Validatecontact(this)">

<input type="hidden" name="formid" value="processorform1">

<label class="label news-update-label">Would you like us to send you news when we have a sale on?</label>

<label class="label news-contact">Name</label>

<input value="" name="text-name" type="text" class="input-1">

<label class="label news-contact">Email Address</label>

<input value="" name="email-name" type="email" class="email-1">

<label class="label news-contact">Captcha</label>

<select class="select drop-down-1" name="indexCombobox1" id="indexCombobox1">
<option>I am a Robot !</option>
<option>I am NOT a Robot!</option>
</select>

<button type="submit" class="button-submit-1" id="indexButton1">Send</button>
</form>

</div>
</div>


Validation Script

<script>
function Validatecontact(theForm)
{
var regexp;
if (theForm.indexCombobox1.selectedIndex < 0)
{
alert("So you are a Robot?");
theForm.indexCombobox1.focus();
return false;
}
if (theForm.indexCombobox1.selectedIndex == 0)
{
alert("So you are a Robot?");
theForm.indexCombobox1.focus();
return false;
}
return true;
}
</script>
KISS is the key!
Burgess Freelance Solutions
User 131545 Photo


Registered User
665 posts

Use WeBuilder good product and it has buildin : PHP, CSS, HTML, JS etc...
Toekomstgerichte door ICT gebeten IT'er
Stephane Fonteyne
Ba. Elektronica - ICT
Application Software PowerBasic Developer
e-mail : stephane.fonteyne@telenet.be
gmail : stephane760126@gmail.com
linkin : in : <http://www.linkedin.com/pub/stephane-fonteyn/53/402/204>
twitter : @Stefke36
User 187934 Photo


Senior Advisor
19,126 posts
Online Now

I don't see where your setting the $_FILES variable.
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2744602 Photo


Registered User
162 posts

STEFKE wrote:
Use WeBuilder good product and it has buildin : PHP, CSS, HTML, JS etc...

It may well be mate :) but I have to do it all the hard way for the course :) MADE BY ME lol Cheers
KISS is the key!
Burgess Freelance Solutions
User 2744602 Photo


Registered User
162 posts

Eric Rohloff wrote:
I don't see where your setting the $_FILES variable.


Is this the section mate?

}
$body = 'This is a multi-part message in MIME format.'.$eol.$eol;
$body .= '--'.$boundary.$eol;
$body .= 'Content-Type: text/plain; charset=ISO-8859-1'.$eol;
$body .= 'Content-Transfer-Encoding: 8bit'.$eol;
$body .= $eol.stripslashes($message).$eol;
if (!empty($_FILES))
{
foreach ($_FILES as $key => $value)
{
if ($_FILES[$key]['error'] == 0 && $_FILES[$key]['size'] <= $max_filesize)
{
$body .= '--'.$boundary.$eol;
$body .= 'Content-Type: '.$_FILES[$key]['type'].'; name='.$_FILES[$key]['name'].$eol;
$body .= 'Content-Transfer-Encoding: base64'.$eol;
$body .= 'Content-Disposition: attachment; filename='.$_FILES[$key]['name'].$eol;
$body .= $eol.chunk_split(base64_encode(file_get_contents($_FILES[$key]['tmp_name']))).$eol;
}
}
}
$body .= '--'.$boundary.'--'.$eol;
KISS is the key!
Burgess Freelance Solutions
User 187934 Photo


Senior Advisor
19,126 posts
Online Now

Where does the variable for this if come from.
if (!empty($_FILES))
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2744602 Photo


Registered User
162 posts

Eric Rohloff wrote:
Where does the variable for this if come from.
if (!empty($_FILES))


Thanks for your help with this mate :) and I have no idea, I know next to nothing about .php :(
However as I stated it works fine until I push it into the exported HTML for the site, my guess is I have missed something or have not linked something correctly.

Does the above code in the HTML seem to link to the processor correctly?
Cheers
KISS is the key!
Burgess Freelance Solutions
User 187934 Photo


Senior Advisor
19,126 posts
Online Now

This variable
$_FILES

is typically set from an upload file input.

http://www.w3schools.com/php/php_file_upload.asp
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2744602 Photo


Registered User
162 posts

Thanks Eric :)
Its a script I was given to use and may well be there if required, no idea really.
I will keep working on it.

At worst I will use an Iframe LOL
KISS is the key!
Burgess Freelance Solutions
User 187934 Photo


Senior Advisor
19,126 posts
Online Now

Where's the script at? If you give a link to the full script I can probably tell you what your missing.
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.