viernes, 29 de agosto de 2014

Enviar correos

Configuración del SMTP:
Opcion 1: http://blog.unijimpe.net/enviar-email-con-php-y-gmail/

Opción 2: http://gidsoft.org/como-configurar-wampserver-para-enviar-correos/

SMTP GMAIL
Código PHP:
1.  $mail->Host = 'smtp.gmail.com';
2.  $mail->Port = 465;
3.  $mail->SMTPAuth = true;
4.  $mail->Username = 'tu_usuario_gmail@gmail.com';
5.  $mail->Password = 'tu_clave_gmail';

SMTP HOTMAIL
Código PHP
1.  $mail->Host = 'smtp.live.com';
2.  $mail->Port = 25;
3.  $mail->SMTPAuth = true;
4.  $mail->Username = 'tu_usuario_hotmail@hotmail.com';
5.  $mail->Password = 'tu_clave_hotmail';

Descripción del comando mail: http://php.net//manual/es/function.mail.php
bool mail ( string $to , string $subject , string $message [, string$additional_headers [, string $additional_parameters ]] )

Ejemplo:
<h2>Feedback Form</h2>
<?php
// display form if user has not clicked submit
if (!isset($_POST["submit"])) {
  ?>
  <form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
  From: <input type="text" name="from"><br>
  Subject: <input type="text" name="subject"><br>
  Message: <textarea rows="10" cols="40" name="message"></textarea><br>
  <input type="submit" name="submit" value="Submit Feedback">
  </form>
  <?php 
} else {    // the user has submitted the form
  // Check if the "from" input field is filled out
  if (isset($_POST["from"])) {
    $from = $_POST["from"]; // sender
    $subject = $_POST["subject"];
    $message = $_POST["message"];
    // message lines should not exceed 70 characters (PHP rule), so wrap it
    $message = wordwrap($message, 70);
    // send mail
    mail("webmaster@example.com",$subject,$message,"From: $from\n");
    echo "Thank you for sending us feedback";
  }
}
?>

viernes, 22 de agosto de 2014

Manejo de archivos en PHP

Ejemplos:
http://blog.deliriumlabs.net/manejo-de-archivos-con-php-y-mysql/

Subir archivos:
index.php
<form action="tuarchivo.php" method="post" name="tuarchivo"
     enctype="multipart/form-data">
<p>manda tu archivo: <input type="file" name="archivo" /></p>
<p><input type="submit" value="mandar archivo" /></p>
</form>
-------------------------------------------------------------------------------------
tuarchivo.php
<?php
copy($_FILES['archivo']['tmp_name'],$_FILES['archivo']['name']);
echo "Tu archivo se ha guardado en nuesto sitio web.";
?>
--------------------------------------------------------------------------------------

Insertar una imagen:
<?php
echo "<img src=\"imagen.jpg\" height= 200 width=150>";
?>

Filtrar extensiones
#extention filter
$allowed = array("image/gif","image/png");  
if(!in_array($files,$allowed)){
 $error_message = 'Only jpg, gif, and pdf files are allowed.';
  $error = 'yes';
  echo $error_message;
  exit();
}   #extention