1

Resulta que estoy haciendo una web y no se como hacer que desde el formulario de html se envie a un php que lo envie a mi email ya que no me deja (o si hay una forma más facil, sin php o algo ) no me da ningun error sino que directamente no envia el email agradeceria que me ayudaseis :D Utilizo infinityfree para hostear la pagina web. aqui dejo los codigos:

Codigo html del Formulario

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>INICIO - DARKTEAM</title>
    <style>
        body {
            font-family:Arial;
            background-color: #f2f2f2;
        }
        .header{
            padding: 80px;
            text-align: center;
            background: #1abc9c;
            color: white;   
        }
        .header h1{
            font-size: 40px;
        }
        .navbar{
            overflow: hidden;
            background-color: #333;
        }
        .navbar a{
            float: left;
            display: block;
            color: white;
            text-align: center;
            padding: 14px 20px;
            text-decoration: none;
        }
        .navbar a.right {
            float: right; 
        }
        .navbar a:hover {
            background-color: #ddd; 
            color: black; 
        }
        .row {
            display: flex;
            flex-wrap: wrap;
        }
        .side {
            flex: 30%; 
            background-color: #f1f1f1; 
            padding: 20px; 
        }
        .main {
            flex: 70%;
            background-color: white; 
            padding: 20px; 
        }
        @media screen and (max-width: 700px) {
            .row {
                flex-direction: column;
            }
        }
        @media screen and (max-width: 400px) {
            .navbar a {
                float: none;
                width: 100%;
            }
        }
        .footer {
            padding: 20px;
            text-align: center; 
            background: #ddd; 
        }
        input[type=text], select, textarea{
            width: 100%;
            padding: 12px;
            border: 1px solid #ccc;
            margin-top: 6px;
            margin-bottom: 16px;
            resize: vertical;
        }
        input[type=submit]{
            background-color: #4caf50;
            color: white;
            padding: 12px 20px;
            border: none;
            cursor: pointer;
        }
        input[type=submit]:hover{
            background-color: #45a049;
        }
        .container{
            border-radius: 5px;
            padding: 10px;
        }
        .column{
            float: left;
            width: 60%;
            margin-top: 6px;
            padding: 20px 60px 20px 15px;
            background-color: #f2f2f2;
            border-radius: 5px;
        }
        .row:after {
            content: "";
            display: table;
            clear: both;
        }
        @media screen and (max-width: 600px) {
            .column, input[type=submit] {
                width: 100%;
                margin-top: 0;
            }
        }
    </style>
</head>

<body>
    <div class="header">
        <h1>DARKTEAM</h1>
    </div>
    <div class="navbar">
        <a href="/">LINK</a>
        <a href="/info.html">LINK</a>
        <a href="/contact.html">LINK</a>
        <a href="/" class="right">LINK</a>
    </div>
    <div class="container">
                <div style="text-align=center">
                    <h2>CONTACTANOS</h2>
                </div>
            </div>
    <div class="row">
        <div class="column">
            <form action="/contactform.php">
                <label for="name">Nombre</label>
                <input type="text" id="name" name="name" placeholder="Tu nombre..." required>
                <label for="email">Email</label>
                <input type="text" id="email" name="email" placeholder="[email protected]" required>
                <label for="comment">Comentario</label>
                <textarea id="comment" name="comment" placeholder="Tu comentario..." style="height:170px" required></textarea>
                <input type="submit" value="Enviar">
            </form>
        </div>
        <div class="side">

        </div>

    </div>
     <div class="footer">
        <h2>DARKTEAM.EPIZY.COM</h2>
     </div> 
</body>
</html>

codigo PHP al que redirige el HTML al darle a enviar

<?php

date_default_timezone_set('Etc/UTC');

// Edit this path if PHPMailer is in a different location.
require './PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer;
$mail->isSMTP();

/*
 * Server Configuration
 */

$mail->Host = 'smtp.gmail.com'; // Which SMTP server to use.
$mail->Port = 587; // Which port to use, 587 is the default port for TLS security.
$mail->SMTPSecure = 'tls'; // Which security method to use. TLS is most secure.
$mail->SMTPAuth = true; // Whether you need to login. This is almost always required.
$mail->Username = "[email protected]"; // Your Gmail address.
$mail->Password = ""; // Your Gmail login password or App Specific Password.
$mail->SMTPDebug = 2;
/*
 * Message Configuration
 */

$mail->setFrom($email, $name); // Set the sender of the message.
$mail->addAddress('[email protected]', 'TheDarkDragon117'); // Set the recipient of the message.
$mail->Subject = 'FORMULARIO DE CONTACTO'; // The subject of the message.

/*
 * Message Content - Choose simple text or HTML email
 */

// Choose to send either a simple text email...
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$bodyresponse = "Has recibido un Formulario de Contacto de $name - $email \n Aqui esta el comentario: \n $comment";
$mail->MsgHTML($bodyresponse);

// ... or send an email with HTML.
//$mail->msgHTML(file_get_contents('contents.html'));
// Optional when using HTML: Set an alternative plain text message for email clients who prefer that.
//$mail->AltBody = 'This is a plain-text message body'; 

// Optional: attach a file

if ($mail->send()) {
    echo "MENSAJE ENVIADO CORRECTAMENTE :D";
} else {
    echo "Mailer Error: " . $mail->ErrorInfo;
}
?>

EDIT: Ahora tengo otro problema, no se como hacer que las entradas funcionen(el $name $email $comment) ahora he conseguido que me llegue pero en las partes en donde tiene que ir estas entradas me aparece vacio EDIT2: TODOS LOS ERRORES CORREGIDOS, AHORA TODO FUNCIONA BIEN

6
  • please translate your question this is the spanish version of Stack Over Flow
    – user75901
    el 12 mar. 2018 a las 22:12
  • asi mismo te comento pega el código en el editor de textos para que si algún usuario quiere apoyarte y necesita replicar el ejercicio no debra rescribir todo
    – user75901
    el 12 mar. 2018 a las 22:18
  • ¿Y qué error te está dando? ¿Están bien configurados los datos de sendmail o del MTA en el php.ini?
    – Mariano
    el 14 mar. 2018 a las 5:06
  • El envío de emails requiere un servidor SMTP, y en la mayoría de ocasiones, un usuario y contraseña. Éstos se configuran en el php.ini, en la sección [mail function] el 14 mar. 2018 a las 7:00
  • ¿Estás trabajando desde localhost o en un servidor compartido?Si estás en local, es posible que no tengas configurdo el envío de mails. Si estás en un servidor compartido, es posible que tu proveedor no permita el envío de correos mediante scripts. Échale un vistazo a esta respuesta es.stackoverflow.com/a/12970/7478
    – ErnestoRM
    el 14 mar. 2018 a las 7:14

2 respuestas 2

2

puedes usar la librería de phpmailer, sólo necesitas importar los archivos class.phpmailer.php y class.smtp.php. A continuación te comparto un ejemplo configurado con un correo de gmail

<?php	
	require_once('classes/class.phpmailer.php');
	require_once("classes/class.smtp.php");

	$mail = new PHPMailer();
	$mail->CharSet = 'UTF-8';
	$mail->IsSMTP();
	$mail->SMTPDebug  = 0;
	$mail->SMTPAuth   = true;

	// AGREGAR TUS DATOS DE CORREO 
	$mail->SMTPSecure = 'tls';
	$mail->Host       = 'smtp.gmail.com';
	$mail->Port       = '587';
	$mail->Username   = '[email protected]';
	$mail->Password   = '***';
			
	// ------ CONFIGURACIÓN DEL MAIL DE AUTORESPUESTA  -----------
	$mail->SetFrom($mail->Username, 'stackoverflow');
	$mail -> Subject = 'Información recibida de formulario';
	$bodyresponse = "Has recibido un formulario de $name Aqui esta el mensaje comment";
	$mail -> Subject = '¡Gracias por registrarte!';
	$mail->MsgHTML($bodyresponse);
	$mail->ClearAddresses();
	$mail->AddAddress('[email protected]');	

	if(!$mail->Send()){
		echo "Mailer Error: ".  $mail->errorInfo;
	}
	else{
		echo "Mail Enviado";
	}
?>

1
  • No me funciona, este es el codigo que he puesto ahora pastebin.com/xfjbeRy6 y sigue sin enviar nada ni poner nada en pantalla -_-
    – Tsetsi
    el 14 mar. 2018 a las 16:52
0

Hola te comento en dos partes:

1.- En tu código Html le cuando abres tu form le falta especifiques el método para mandar los datos beria quedar algo asi:

2.- En tu archivo php, para que funcione el método mail() debes tener instalada la libreria sendmail.
-si usas ubuntu puedes instalar sendmail con:
sudo apt-get install sendmail

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.