terça-feira, 23 de outubro de 2012

Para Aquecer ( Programacao em PHP) para Aquecer..

Ola.. De algum tempo para ca tenho trabalhado em desenvolver pagina em PHP ... Bem tenho experimentado coisas porque e uma linguagem muito interessante

Aqui estao algums screen-dumps problemas encontrados, quando programando em PHP


Esta foto e tirada do outuput the uma forma feita para mandar e-mail .. tudo escrito em PHP .. Aqui vai um extrato do codigo ...



<?php
/** Contactform1.php
**
** Created with Notepad++ by iTechReload Ltd all rights Reserved
** Open source version Program License under GNU public License
**
**/

?>
<?php

if (isset($_POST['email'])) {
//Enter the destination email details
$email_to = "some@someemail.com";
$email_subject = "subject";

//for testing purpose let this be a comment for now
//function die ($error); {
// if something goes wrong on code it goes here

// echo "There is a error(s) found with your form, please go back and fix it";
// echo "These error(s) appear bellow .<br><br>";
// echo $error."<br><br>";
// echo "Please go back and fix these errors .<br><br>";
// die('Something is not right on your code please debugg it line:25');

//}
//Now validate the data you are sending
/*if (isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['subject']) ||
!isset($_POST['message'])) {
die('Something is not right on your code please debugg it line:33');
}*/

//Now retrieve the information given
$name = $_POST['name']; //this is required
$email_from = $_POST['email']; //this is required
$telephone_number = $_POST['phone']; //this is required
$message = $_POST['message']; //this is required

//Show an error message if something not right
$error_message = "";


$string_exp = "/^[A-Za-z .'-]+$/";
if (!preg_match_all($string_exp, $name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br>';
}

//This script will stop user to enter an invalid email
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if (!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br>';
}

if (strlen($message) < 2) {
$error_message .= 'The message you entered does not appear to be valid.<br>';
}
if(strlen($error_message) > 0) {
die($error_message);
}

$email_message = "Form details bellow.\n\n";

function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}

$email_message .= "Full Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Phone: ".clean_string($telephone_number)."\n";
$email_message .= "Message: ".clean_string($message)."\n";

//Now try to create an email header
$headers = 'From: '.$email_from."\r\n";
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>

<!-- include you own successs html here -->

<?php

//End of the all document
}
?>
<?php header("Location: thank_you.html") ?>

Ok, parece um tanto ou quanto complexo, mas nao e..... Aseguir contrui a pagina em HTMl que ira usar esta forma para poder enviar emails.


HTML coding;

<body>
<div id="toptabs">
<p>Site Network: 
<a class="toptab" href="index.html">ItechReload</a><span class="hide"> | </span>
<a class="toptab" href="index.html">About us</a><span class="hide"> | </span>
<a class="activetoptab" href="contactus.html">Contact Us</a></p>
</div>

<div id="container">
<div id="logo"><img src="Logo.jpg"align="middle" />
</div>

<div id="navitabs">
<h2 class="hide">Site menu:</h2>
<a class="navitab" href="index.html">Welcome</a><span class="hide"> | </span>
<a class="navitab" href="OurServices.html">Services</a><span class="hide"> | </span>
<a class="navitab" href="OurPortofolio.html"> Portfolio</a><span class="hide"> | </span>
<a class="activenavitab" href="contactus.html">Contact us</a><span class="hide"> | </span>
<!--<a class="navitab" href="#">Our Clients</a><span class="hide"> | </span>-->
<!--<a class="navitab" href="#">Our Patners</a><span class="hide"> | </span>-->
</div>
<div id="desc">
<br>
<p></p>
<p></p>
<p><strong>Please leave us your message !</strong></p>
<!--<p class="right"><a href="#">Read more...</a></p>-->
<form name="form1" method="post" action="contactform1.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td>Name</td>
<td>:</td>
<td><input name="name" type="text" id="name" size="25"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" id="email" size="25"></td>
</tr>
<tr>
<td>Phone Number</td>
<td>:</td>
<td><input name="phone" type="text" id="phone" size="15"></td>
</tr>
<tr>
<td width="16%">Subject</td>
<td width="2%">:</td>
<td width="82%">
   <input name="subject" type="text" id="subject" size="30">
</td>
</tr>
<tr>
<td>Detail</td>
<td>:</td>
<td>
<textarea name="message" cols="50" rows="15" id="message">
</textarea>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>
<input type="submit" name="Submit" value="Submit"> 
<input type="reset" name="Submit2" value="Reset">
</td>
</tr>
</table>
</form>
</div>
<div id="main">
</div>
<div id="footer">
Copyright &copy; 2011. Design by <a href="http://iTechReload.co.uk">iTechReload Ltd</a>.
</div>
</div>
</body>
</html>

..... Preciso dizer aqui que esta forma esta a funcionar a 70% ainda existem alguns bugs que preciso resolver... a forma esta localizada neste site ao vivo, com o endereco http://www.itechreload.co.uk/

Ainda exitem alguns erros que sera preciso resolver como este ...