Jump to content
Programar2020

PHPMailer

Recommended Posts

Programar2020

Boa Tarde

Sou novo na programação, precisava de ajuda nesta situação. O objetivo deste exercício é enviar os dados preenchidos no formulário para um determinado email pré-definido através da função PHPMAILER.

Código da Reserva Online
 

<section class="section section_reservation mt-5" id="reservation">
<div class="container">
<div class="row">
<div class="col">
<h2 class="text-center">Reserva Online</h2>
</div>
</div>
<div class="row justify-content-lg-center section_reservation__row">
<div class="col-lg-8">
<form class="section_reservation__form" action="" method="post">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="sr-only">Nome Completo</label>
<input type="text" class="form-control" name="name" placeholder="Nome Completo" required>
</div>
<div class="form-group">
<label class="sr-only">Telemóvel</label>
<input type="tel" class="form-control" name="tel" placeholder="Telemóvel" required>
</div>
<div class="form-group">
<label class="sr-only">E-mail</label>
<input type="email" class="form-control" name="email" placeholder="E-mail" required>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="sr-only">Pessoas</label>
<select class="form-control" name="people">
<option value="1">1 pessoa</option>
<option value="2">2 pessoas</option>
<option value="3">3 pessoas</option>
<option value="4">4 pessoas</option>
<option value="5">5 pessoas</option>
</select>
</div>
<div class="form-group">
<label class="sr-only">Data</label>
<input type="date" class="form-control" name="date" required>
</div>
<div class="form-group">
<label class="sr-only">Time</label>
<input type="time" class="form-control" name="time" required>
</div>
</div>
<div class="col">
<div class="text-center">
<button type="submit" class="btn btn-primary">Reserve</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</section>

 

Dúvida: <form class="section_reservation__form" action="" method="post"> ( não sei o que colocar entre os parênteses do action)

reservation.php

<?php

if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(!isset($_POST['name']) ||
!isset($_POST['tel']) ||
!isset($_POST['email']) ||
!isset($_POST['people']) ||
!isset($_POST['date']) ||
!isset($_POST['time']) )
{
// Recarregar toda a página redirecionando para o formulário, apresentado de novo todos os campos.
header('Location: index.html#reservation');
}
}
$name = $_POST['name'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$people = $_POST['people'];
$date = $_POST['date'];
$time = $_POST['time'];

A validação que fiz não está a funcionar.

email.php (Função PHPMAILER)
 

<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

$mail = new PHPMailer(true);

try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '';
$mail->Password = '';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;

//Recipients
$mail->setFrom('', '');
$mail->addAddress($email, 'Destinatário');

// Content
$mail->isHTML(true);
$mail->Subject = 'Reserva Online';
$mail->Body = $name . $tel . $email . $people . $date . $time;
;
// $mail->AltBody = '';

$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

Mas parece que não funciona o que fiz! Alguém me pode ajudar neste problema.

Abraço

Share this post


Link to post
Share on other sites
M6

Tens de analisar o erro que estás a obter para saberes o que estás a fazer mal, mas assim de cabeça, pelo que me recordo, o stmp do gmail só funciona com autenticação.

  • Vote 1

10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Share this post


Link to post
Share on other sites
Programar2020

Já consegui resolver! Obrigado pela ajuda. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. 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.