Authenticated SMTP PHP code - php

I'm new in coding in PHP and I've been trying to figure out how to send contact form data through a SMTP authenticated PHP script. So far, it's been very frustating and I couldn't do it.
I have this bootstrap form on an HTML page and I don't know how to create the contact.php script to send it with SMTP authenticated.
<form id="contact-form" method="post" action="contato.php" role="form">
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="form-group">
<label for="form_name">Nome:</label>
<input id="form_name" type="text" name="name" class="form-control" placeholder="Qual o seu nome?" required="required" data-error="Você precisa informar seu nome.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="row">
<div class="form-group">
<label for="form_email">Email:</label>
<input id="form_email" type="email" name="email" class="form-control" placeholder="Qual o seu e-mail?" required="required" data-error="Insira um e-mail válido.">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label for="form_phone">Fone:</label>
<input id="form_phone" type="tel" name="phone" class="form-control" placeholder="Qual o seu telefone?">
<div class="help-block with-errors"></div>
</div>
`enter code here`</div>
<div class="row">
<div class="form-group">
<label for="form_message">Mensagem:</label>
<textarea id="form_message" name="message" class="form-control" placeholder="Mensagem para o Rancho" rows="4" required="required" data-error="Qual a sua mensagem?"></textarea>
<div class="help-block with-errors"></div>
</div>
<input type="submit" class="btn btn-success btn-send" value="Enviar">
</div>
</div>
</form>
My contato.php
<?php
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.ranchopremier.com.br";
$mail->SMTPAuth = true;
$mail->Username = 'contato#ranchopremier.com.br';
$mail->Password = 'mypass';
$mail->SMTPSecure = 'tls';
$mail->From = "contato#ranchopremier.com.br";
$mail->Sender = "contato#ranchopremier.com.br";
$mail->FromName = "Locaweb";
$mail->AddAddress('contato#ranchopremier.com.br', 'Teste Locaweb');
$mail->AddAddress('id#live.com');
$mail->IsHTML(true);
$mail->Subject = "CONTATO DO SITE";
$mail->Body = 'Este é o corpo da mensagem de teste, em HTML!;
$mail->AltBody = 'Este é o corpo da mensagem de teste, em Texto Plano! \r\n;
$enviado = $mail->Send();
$mail->ClearAllRecipients();
$mail->ClearAttachments();
if ($enviado) {
echo "E-mail enviado com sucesso!";
} else {
echo "Não foi possível enviar o e-mail.";
echo "Informações do erro:" . $mail->ErrorInfo;
}
?>
If anyone would like to help I will appreciate.
Thanks

Related

Problem in transmitting data from an HTML / PHP form

Good evening to all,
I did a project with Argon (Bootstrap / vue.js). This is a SPA with a contact section including a contact form (name, email, message). My contact form, is established on a .vue file, who is imported into my index.html:
<form class="needs-validation col-md-8 from-right" novalidate id="myForm" method="post" action="./index.php">
<div class="form-column">
<div>
<label for="nom">Saisissez votre nom</label>
<input type="text" class="form-control" id="nom" required placeholder="Votre nom" name="nom">
<div class="valid-feedback">
C'est noté!
</div>
<div class="invalid-feedback">
Merci de saisir votre nom.
</div>
</div>
<div>
<label for="email" class="mt-3">Saisissez votre email</label>
<input type="email" class="form-control" id="email" placeholder="Votre email" name="email" required>
<div class="valid-feedback">
C'est noté!
</div>
<div class="invalid-feedback">
Merci de saisir un email valide.
</div>
</div>
<div>
<label for="message" class="mt-3">Saisissez votre message</label>
<textarea class="form-control" id="message" placeholder="Votre message ici" name="message" required></textarea>
<div class="valid-feedback">
C'est noté!
</div>
<div class="invalid-feedback">
Merci de saisir votre message.
</div>
</div>
</div>
<button class="btn btn-primary my-5 mx-auto" type="submit">Envoyer</button>
<div id="retourenvoimessage"></div>
</form>
I established an index.php file, supposed to retrieve the data from the HTML form, and forward it to me by email. I apologize in advance if my code offends PHP enthusiasts, for my part I do not know this language at all for the moment and have tried to get by by drawing on some documentation:
<?php
$nom = $_POST['nom'];
$email = $_POST['email'];
$message = $_POST['message'];
$dest = "fer.mathieu#gmail.com";
$sujet = "Demande de contact";
$corp = "Nom : $nom\n Email : $email\n Message : $message";
$headers = "From: $nom\n Reply-To: $email";
if (mail($dest, $sujet, $corp, $headers)) {
?><script>document.querySelector('#retourenvoimessage').textContent="Message bien envoyé, merci!"</script><?php
} else {
?><script>alert("Oups, un problème est survenu lors de l'envoi du message, désolé...");document.location.href="http://www.namesite.com/"</script><?php
}
?>
My wish was that during the submission, if successful, a message is added specifying the sending.
I have a javascript function which prevents the default behavior and therefore does not reload the page when submitting.
Yesterday I put my project online, and there "is the drama". When I fill in the fields of the form and submit it, firstly no message is added as wanted, but well that's not what bothers me the most.
I did receive an email from my host, containing the requested fields ('Name:', 'Email:', 'Message: "), but these are empty.
After much research on the net, not being able to find an answer to my problem, I motivate myself to post this one, at the risk of being hit with sticks if the problem, my mistake, was very simple Smiley confused.
Thank you in advance and sorry for my bad english.
The problem is probably caused by my Vue file. I do a new php file with PhpMailer, who works well in local mode. But when i submit my form, i no longer receive email as expected.
My Vue.js file:
<form class="needs-validation col-md-8 from-right" novalidate id="myForm" method="post" action="index.php">
<div class="form-column">
<div>
<label for="nom">Saisissez votre nom</label>
<input v-model="nom" type="text" class="form-control" id="nom" required placeholder="Votre nom" name="nom">
<div class="valid-feedback">
C'est noté!
</div>
<div class="invalid-feedback">
Merci de saisir votre nom.
</div>
</div>
<div>
<label for="email" class="mt-3">Saisissez votre email</label>
<input v-model="email" type="email" class="form-control" id="email" placeholder="Votre email" name="email" required>
<div class="valid-feedback">
C'est noté!
</div>
<div class="invalid-feedback">
Merci de saisir un email valide.
</div>
</div>
<div>
<label for="message" class="mt-3">Saisissez votre message</label>
<textarea v-model="message" class="form-control" id="message" placeholder="Votre message ici" name="message" required></textarea>
<div class="valid-feedback">
C'est noté!
</div>
<div class="invalid-feedback">
Merci de saisir votre message.
</div>
</div>
</div>
<button class="btn btn-primary my-5 mx-auto" type="submit">Envoyer</button>
</form>
</div>
</section>
</template>
<script>
import BaseNav from "#/components/BaseNav";
import CloseButton from "#/components/CloseButton";
export default {
name: 'Contact',
data(){
return {
nom: '',
email: '',
message: ''
}
}
};
</script>
My PHP file:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'lib/PHPMailer/src/Exception.php';
require 'lib/PHPMailer/src/PHPMailer.php';
require 'lib/PHPMailer/src/SMTP.php';
$nom = $_POST['nom'];
$email = $_POST['email'];
$message = $_POST['message'];
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'myadress#gmail.com';
$mail->Password = 'mypassword';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
//Recipients
$mail->setFrom($email, $nom);
$mail->addAddress('myadress#gmail.com');
// Content
$mail->isHTML(true);
$mail->Subject = 'Contact via portfolio';
$mail->Body = "Nom : $nom\n
Email : $email\n
Message : $message";
$mail->send();
echo 'Message bien envoyé';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
The Javascript function for the form:
(function() {
'use strict';
window.addEventListener('load', function() {
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName('needs-validation');
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function(form) {
form.addEventListener('submit', function(event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();

Empty fields on a form will consider a pre existing value

I have a website where the user can create a profile. However, if he decides to make any alteration on that profile, he can go to alterar_cadastro.php and make that changes he desire. Code of the file bellow:
<?php
session_start();
include('verifica_login.php');
$email = $_SESSION['usuario'];
$busca_nivel = "SELECT * FROM cadastro WHERE email = '$email' OR sobrenome = '$email'";
$resultado_busca_nivel = mysqli_query($conexao, $busca_nivel);
$rows = mysqli_fetch_array($resultado_busca_nivel);
?>
<html>
<head>
</head>
<body>
<div class="row">
<div class="col-1"></div>
<div class="col-10">
<br>
<h3>Preencha os dados abaixo para alterar seu cadastro:</h3>
<br>
<form method="post" action="processa_alteracao.php" enctype="multipart/form-data">
<div class="form-group">
<label for="nome">Nome: </label>
<input class="form-control" type="text" name="nome" placeholder="<?php echo $rows['nome'] ?>"><br>
</div>
<div class="form-group">
<label class="form-group">Apelido: </label>
<input class="form-control" type="text" name="sobrenome" placeholder="<?php echo $rows['sobrenome'] ?>">
<small class="form-text text-muted">Atenção! Mudar seu apelido significa mudar o seu login.</small>
</div>
<div class="form-group">
<label for="nome">Cidade: </label>
<input class="form-control" type="text" name="cidade" placeholder="<?php echo $rows['cidade'] ?>"><br>
</div>
<div class="form-group">
<label class="form-group">Estado: </label>
<input class="form-control" type="text" name="estado" placeholder="<?php echo $rows['estado'] ?>">
<small class="form-text text-muted">Escreva o seu estado de forma abreviada. Ex.: AM, AC, DF, TO.</small>
</div>
<div class="form-group">
<label class="form-group">Quem é você? </label>
<textarea class="form-control" rows="5" name="geral" placeholder="<?php echo $rows['geral'] ?>"></textarea>
<small class="form-text text-muted">Nos fale um pouquinho sobre quem é você e o que espera da nossa plataforma :) Máximo de caracteres: 100.</small>
</div>
<div class="form-group">
<label class="form-group">E-mail: </label>
<input class="form-control" type="text" name="email" placeholder="<?php echo $rows['email']; ?>" readonly>
</div>
<div class="form-group">
<label class="form-group">Foto para o perfil: </label><input type="file" name="foto_perfil">
</div>
<div class="form-group">
<label class="form-group">Senha: </label><input class="form-control" type="password" name="senha" placeholder="Insira sua senha para confirmar"><br><br>
<button class="btn btn-primary" type="submit">Alterar Perfil</button>
</div>
</form>
</div>
<div class="col-1"></div>
</div>
</body>
</html>
However, if the user leaves one of the inputs blank, that's the value going to MYSQL. I put bellow the php file that process this information:
<?php
session_start();
include 'db.php';
$email = $_SESSION['usuario'];
$nome = mysqli_real_escape_string($conexao, $_POST['nome']);
$sobrenome = mysqli_real_escape_string($conexao, $_POST['sobrenome']);
$cidade = mysqli_real_escape_string($conexao, $_POST['cidade']);
$estado = mysqli_real_escape_string($conexao, $_POST['estado']);
$geral = mysqli_real_escape_string($conexao, $_POST['geral']);
$perfil = $_FILES['foto_perfil'];
$senha = mysqli_real_escape_string($conexao, $_POST['senha']);
$query_cad = "SELECT * FROM cadastro WHERE email = '$email' AND senha = '$senha' OR sobrenome = '$sobrenome' AND senha = '$senha'";
$result = mysqli_query($conexao, $query_cad);
$row = mysqli_num_rows($result);
$row2 = mysqli_fetch_array($result);
$fk_cad = $row2['entry_cod_cad'];
if($row == 1) {
if(isset($perfil)){
$extensao = strtolower(substr($_FILES['foto_perfil']['name'], -4));
$novo_nome = md5(time()) . $extensao;
$diretorio = "img/perfil/";
move_uploaded_file($_FILES['foto_perfil']['tmp_name'], $diretorio.$novo_nome);
}
$query = "UPDATE cadastro SET nome = '$nome', sobrenome = '$sobrenome', cidade = '$cidade', estado = '$estado', geral = '$geral', perfil = '$novo_nome' WHERE entry_cod_cad = '$fk_cad'";
$result_alteracao = mysqli_query($conexao, $query);
$msg = "success";
echo "<script>alert('$msg');window.location.assign('/index.php?pagina=perfil');</script>";
} else {
$msg = "incorrect";
echo "<script>alert('$msg');window.location.assign('/index.php?pagina=inicio');</script>";
}
My question is: How do I make the empty fields have a pre existing value, where this value is the one that already is in his profile. I thought that the value attribute inside <input> would do the trick, however, I was not successful.
Use value parameter instead of placeholder
<?php
session_start();
include('verifica_login.php');
$email = $_SESSION['usuario'];
$busca_nivel = "SELECT * FROM cadastro WHERE email = '$email' OR sobrenome = '$email'";
$resultado_busca_nivel = mysqli_query($conexao, $busca_nivel);
$rows = mysqli_fetch_array($resultado_busca_nivel);
?>
<html>
<head>
</head>
<body>
<div class="row">
<div class="col-1"></div>
<div class="col-10">
<br>
<h3>Preencha os dados abaixo para alterar seu cadastro:</h3>
<br>
<form method="post" action="processa_alteracao.php" enctype="multipart/form-data">
<div class="form-group">
<label for="nome">Nome: </label>
<input class="form-control" type="text" name="nome" value="<?php echo $rows['nome'] ?>"><br>
</div>
<div class="form-group">
<label class="form-group">Apelido: </label>
<input class="form-control" type="text" name="sobrenome" value="<?php echo $rows['sobrenome'] ?>">
<small class="form-text text-muted">Atenção! Mudar seu apelido significa mudar o seu login.</small>
</div>
<div class="form-group">
<label for="nome">Cidade: </label>
<input class="form-control" type="text" name="cidade" value="<?php echo $rows['cidade'] ?>"><br>
</div>
<div class="form-group">
<label class="form-group">Estado: </label>
<input class="form-control" type="text" name="estado" value="<?php echo $rows['estado'] ?>">
<small class="form-text text-muted">Escreva o seu estado de forma abreviada. Ex.: AM, AC, DF, TO.</small>
</div>
<div class="form-group">
<label class="form-group">Quem é você? </label>
<textarea class="form-control" rows="5" name="geral" value="<?php echo $rows['geral'] ?>"></textarea>
<small class="form-text text-muted">Nos fale um pouquinho sobre quem é você e o que espera da nossa plataforma :) Máximo de caracteres: 100.</small>
</div>
<div class="form-group">
<label class="form-group">E-mail: </label>
<input class="form-control" type="text" name="email" value="<?php echo $rows['email']; ?>" readonly>
</div>
<div class="form-group">
<label class="form-group">Foto para o perfil: </label><input type="file" name="foto_perfil">
</div>
<div class="form-group">
<label class="form-group">Senha: </label><input class="form-control" type="password" name="senha" placeholder="Insira sua senha para confirmar"><br><br>
<button class="btn btn-primary" type="submit">Alterar Perfil</button>
</div>
</form>
</div>
<div class="col-1"></div>
</div>
</body>
</html>

Message body empty in contact form (using PhPMailer)

I'm having a little problem with my contact form.
I'm using PhpMailer and Bootstrap contact form. When I run the code I get this message:
"Uncaught exception 'phpmailerException' with message 'Message body empty'"
This is my code:
$name = $_POST['InputName'];
$company = $_POST['InputFirma'];
$email = $_POST['InputEmail'];
$phone = $_POST['InputPhone'];
$message = $_POST['InputSubject'];
require '../../PHPMailer-master/PHPMailerAutoload.php';
require '../../PHPMailer-master/class.smtp.php';
$mail = new PHPMailer(true);
$mail->SMTPDebug = false; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'poczta.cgsa.com.pl'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'sample#sample.pl'; // SMTP username
$mail->Password = 'FU86m6BSp7'; // SMTP password
$mail->Port = 587;
$mail->setFrom('sample#sample.pl', 'Giełd');
$mail->addAddress('sample#sample.pl', 'Odbiorca'); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
if(!$mail->send()) {
echo 'Wiadomość nie mogła zostać wysłana';
echo "<br><br><br><hr><br>";
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Wiadomość została wysłana';
}
$Body = "Wiadomość od: $name\n E-Mail: $email\n Firma: $company\n";
$success = mail($name, $company, $phone, $message);
This is my HTML:
<form class="padding-top-40" role="form" id="contactForm" class="contact-form" data-toggle="validator" class="shake">
<div class="form-group">
<label for="InputName">Imię i nazwisko</label>
<input type="text" class="form-control" id="InputName" name="fullname" placeholder="Imię i nazwisko" required data-error="Proszę wpisać swoje imię i nazwisko">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label for="InputFirma">Firma</label>
<input type="text" class="form-control" id="InputFirma" name="subject" name="comments" placeholder="Firma" required data-error="Proszę wpisać nazwę firmy">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label for="InputEmail">E-mail</label>
<input type="email" class="form-control" id="InputEmail" name="emailid" placeholder="E-mail" required data-error="Proszę wpisać swój email">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label for="InputPhone">Telefon kontaktowy</label>
<input type="number" class="form-control" name="phone" id="InputPhone" placeholder="Numer telefonu" required data-error="Proszę wprowadzić numer telefonu">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label for="InputSubject">Temat</label>
<textarea type="text" class="form-control" name="subject" id="InputSubject" placeholder="Treść wiadomości" rows="4" required data-error="Proszę wpisać treść wiadomości"></textarea>
<div class="help-block with-errors"></div>
</div>
<div class="padding-top-20">
<button type="submit" value="send" class="btn btn-default" id="submit" >Wyślij</button>
<div id="msgSubmit" class="h3 text-center"></div>
</div>
</form>
Question
How can I address the error message?
You're just doing things in the wrong order. You need to set the Body property (and not just a variable called $Body) before you send the message, and you don't need to call mail() at all.
$mail->Body = "Wiadomość od: $name\n E-Mail: $email\n Firma: $company\n";
if(!$mail->send()) {
echo 'Wiadomość nie mogła zostać wysłana';
echo "<br><br><br><hr><br>";
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Wiadomość została wysłana';
}
You're using the auoloader, so you don't need to require the SMTP class separately, it will be loaded automatically.
You are enabling exceptions (by passing true in the constructor), but you are not wrapping your code in a try/catch block to deal with any that may happen.

PHP in bootstrap form not working

I have been trying to add php to a bootstrap form via the following tutorial: https://bootstrapbay.com/blog/working-bootstrap-contact-form/. But nothing happens when I click the submit button - I just go back/stay to the same page with an empty form. I don't receive an email nor any error actions when I don't fill out some fields either. Below my code. The name of the document is werkwijze.php. Does someone have an idea what I'm doing wrong? Thanks a lot in advance!
<?php
if (isset($_POST['submit'])){
$voornaam = $_POST['voornaam'];
$familienaam = $_POST['familienaam'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$vraag = $_POST['vraag'];
$from = 'info#tbep.be';
$to = 'eefje.vanhemelryck#gmail.com';
$subject = 'Vraag van op uw website www.tbep.be';
$body = "From: $voornaam $familienaam\n E-Mail: $email\n Telefoon: $tel\n Vraag: $vraag";
// Check if name has been entered
if (!$_POST['voornaam']) {
$errVoornaam = 'Gelieve uw voornaam op te geven';
}
if (!$_POST['familienaam']) {
$errFamilienaam = 'Gelieve uw familienaam op te geven';
}
// Check if email en phone has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Gelieve uw emailadres op te geven';
}
if (!$_POST['tel']) {
$errTel = 'Gelieve uw telefoonnummer op te geven';
}
//Check if message has been entered
if (!$_POST['vraag']) {
$errVraag = 'Gelieve uw vraag te stellen';
}
// If there are no errors, send the email
if (!$errVoornaam && !$errFamilienaam && !$errEmail && !$errTel && !$errVraag) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Hartelijk dank. Ik neem zo snel mogelijk contact met u op!</div>';
} else {
$result='<div class="alert alert-danger">Sorry, er was een probleem met het versturen van dit formulier. Alternatief kan u ons een email sturen op info#tbep.be</div>';
}
}
}
?>
<form class="form-horizontal" role="form" action="werkwijze.php" method="post" enctype="text/plain">
<div class="form-group">
<label class="control-label col-sm-3" for="voornaam">Voornaam:</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="voornaam" name="voornaam" placeholder="Voornaam">
<?php echo "<p class='text-danger'>$errVoornaam</p>";?>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="familienaam">Familienaam:</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="familienaam" name="familienaam" placeholder="Familienaam">
<?php echo "<p class='text-danger'>$errFamilienaam</p>";?>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="email">Email:</label>
<div class="col-sm-9">
<input type="email" class="form-control" id="email" name="email" placeholder="Email">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="telefoon">Telefoonnummer:</label>
<div class="col-sm-9">
<input type="tel" class="form-control" id="tel" name="tel" placeholder="Telefoonnummer">
<?php echo "<p class='text-danger'>$errTel</p>";?>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="vraag">Uw vraag:</label>
<div class="col-sm-9">
<textarea class="form-control" rows="5" id="vraag" name="vraag" placeholder="Uw vraag"></textarea>
<?php echo "<p class='text-danger'>$errVraag</p>";?>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<button type="submit" id="submit" name="submit" value="Send" class="btn btn-default">Versturen</button>
</div>
</div>
<div class="form-group">
<div class="col-sm-9 col-sm-offset-3">
<?php echo $result; ?>
</div>
</div>
</form>
Please Remove enctype="text/plain" from your form.
<form class="form-horizontal" role="form" action="werkwijze.php" method="post">
Or use
<form class="form-horizontal" role="form" action="werkwijze.php" method="post" enctype="multipart/form-data">

Get checkbox value on pgp email form

I got this code working (i´m not programmer, but I really need this), it´s sending email with all values, but the checkbox values are blank on the email, even when they´re checked... any help please?
important: serv-opcao(x) and doc-opcao(x) are the ckeckboxes names.
<?php
$nome = $_POST['nome'];
$email = $_POST['email'];
$telefone = $_POST['telefone'];
$serv_opcao1 = $_POST[serv-opcao1];
$serv_opcao2 = $_POST[serv-opcao2];
$serv_opcao3 = $_POST[serv-opcao3];
$serv_opcao4 = $_POST[serv-opcao4];
$serv_opcao5 = $_POST[serv-opcao5];
$serv_opcao6 = $_POST[serv-opcao6];
$serv_opcao7 = $_POST[serv-opcao7];
$outros = $_POST[outros];
$slogan = $_POST[slogan];
$url = $_POST[url];
$doc_opcao1 = $_POST[doc-opcao1];
$doc_opcao2 = $_POST[doc-opcao2];
$doc_opcao3 = $_POST[doc-opcao3];
$doc_opcao4 = $_POST[doc-opcao4];
$doc_opcao5 = $_POST[doc-opcao5];
$doc_opcao6 = $_POST[doc-opcao6];
$outros = $_POST[outros2];
$mensagem1 = $_POST[mensagem1];
$mensagem2 = $_POST[mensagem2];
$mensagem3 = $_POST[mensagem3];
$emaildestino = 'lucasvallimdacosta#me.com';
$email_from='lucasvallimdacosta#me.com';
$mensagem = $_POST['mensagem'];
$assunto = $_POST['assunto'];
$titulo = 'Site Lucas Vallim - Nova Mensagem';
$juntando = '<p>Esta mensagem foi enviada pelo site</p><br/>
<p><b>Nome:</b> '.$nome.'</p>
<p><b>Email:</b> '.$email.' </p>
<p><b>Telefone:</b> '.$telefone.'</p>
<p><b>Serviços desejados:</b></p>
<p> '.$serv_opcao1.' '.$serv_opcao2.' '.$serv_opcao3.' '.$serv_opcao4.' '.$serv_opcao5.' '.$serv_opcao6.' '.$serv_opcao7.' </p>
<p><b>Outros (se houver):</b> '.$outros.'</p>
<p><b>Slogan:</b>'.$slogan.'</p>
<p><b>Url:</b>'.$url.'</p>
<p><b>Documentação disponível:</b></p>
<p> '.$doc_opcao1.' '.$doc_opcao2.' '.$doc_opcao3.' '.$doc_opcao4.' '.$doc_opcao5.' '.$doc_opcao6.'</p>
<p><b>Outros (se houver):</b> '.$outros2.'</p>
<p><b>Existe hoje algum problema de comunicação com o público-alvo?</b></p>
<p>'.$mensagem1.'</p>
<p><b>Você pretende que o trabalho esteja pronto em quanto tempo?</b></p>
<p>'.$mensagem2.'</p>
<p><b>Descreva, com suas palavras, tudo sobre o serviço desejado</b></p>
<p>'.$mensagem3.'</p>
<hr>';
$headers = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
$headers .= "From: $email_from " . "\n";
$envio = mail($emaildestino, $titulo, $juntando, $headers, "-r".$email_from);
if($envio)
header('Location:http://www.google.com');
else
echo "A mensagem não pode ser enviada";
?>
here´s the HTML form:
<form method="POST" name="contactform" id="meu_form" class="form-horizontal" action="design.php">
<br>
<fieldset>
<legend>Dados Pessoais</legend>
<div class="control-group">
<label class="control-label" for="inputNome">Nome</label>
<div class="controls">
<input type="text" name="nome" id="nome" id="inputNome" placeholder="">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input type="text" name="email" id="email" id="inputEmail" placeholder="">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputTelefone">Telefone</label>
<div class="controls">
<input type="text" name="telefone" id="telefone" id="inputTelefone" placeholder="">
</div>
</div>
</fieldset>
<br>
<fieldset id="fundo_safari">
<legend>Formulário para criação de <b>Design Gráfico</b></legend>
<div class="control-group">
<label class="control-label" for="inputPassword">Qual o serviço de interesse?<br>
</label>
<div class="controls">
<label class="checkbox">
<input type="checkbox" name="serv-opcao1" id="serv-opcao1" value="Cartão de Visitas">
Cartão de Visitas
</label>
<label class="checkbox">
<input type="checkbox" name="serv-opcao2" id="serv-opcao2" value="Banner">
Banner
</label>
<label class="checkbox">
<input type="checkbox" name="serv-opcao3" id="serv-opcao3" value="Folheto">
Folheto
</label>
<label class="checkbox">
<input type="checkbox" name="serv-opcao4" id="serv-opcao4" value="Papel Timbrado">
Papel Timbrado
</label>
<label class="checkbox">
<input type="checkbox" name="serv-opcao5" id="serv-opcao5" value="Pasta Institucional">
Pasta Institucional
</label>
<label class="checkbox">
<input type="checkbox" name="serv-opcao6" id="serv-opcao6" value="Assinatura de Email">
Assinatura de e-mail
</label>
<label class="checkbox">
<input type="checkbox" name="serv-opcao7" id="serv-opcao7" value="Outros">
Outros
</label>
<input type="text" name="outros" id="outros" id="inputOutros" placeholder="Especifique">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEndereço">Possui um slogan?<span id="complemento_label"> (se houver, indique qual).</span></label>
<div class="controls">
<input type="text" name="slogan" id="slogan" placeholder="">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEndereço">Endereço do website atual<span id="complemento_label"> (se houver).</span></label>
<div class="controls">
<div class="input-prepend">
<span class="add-on">http://</span>
<input type="text" id="url" name="url" id="inputNome" placeholder="">
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Qual a documentação disponível?<br>
</label>
<div class="controls">
<label class="checkbox">
<input type="checkbox" name="doc-opcao1" id="doc-opcao1" value="Logo Tipo">
Logotipo
</label>
<label class="checkbox">
<input type="checkbox" name="doc-opcao2" id="doc-opcao2" value="Impresso Institucional">
Impresso Institucional
</label>
<label class="checkbox">
<input type="checkbox" name="doc-opcao3" id="doc-opcao3" value="Manual">
Manual
</label>
<label class="checkbox">
<input type="checkbox" name="doc-opcao4" id="doc-opcao5" value="Fotos">
Fotos
</label>
<label class="checkbox">
<input type="checkbox" name="doc-opcao5" id="doc-opcao5" value="Videos">
Videos
</label>
<label class="checkbox">
<input type="checkbox" name="doc-opcao6" id="doc-opcao6" value="Outros">
Outros
</label>
<input type="text" name="outros2" id="outros2" id="inputOutros" placeholder="Especifique">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Existe hoje algum problema de comunicação com o público-alvo?
</label>
<div class="controls">
<textarea rows="4" name="mensagem1" id="mensagem1"></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Você pretende que o trabalho esteja pronto em quanto tempo? <span id="complemento_label">(Prazo máximo)</span>
</label>
<div class="controls">
<textarea rows="4" name="mensagem2" id="mensagem2"></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Descreva, com suas palavras, tudo sobre o serviço desejado <span id="complemento_label">(objetivo, funcionalidade, exigências, etc.)</span>
</label>
<div class="controls">
<textarea rows="4" name="mensagem3" id="mensagem3"></textarea>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary">Enviar</button>
</div>
</div>
</fieldset>
</form>
Hint by simple code highlighting:
$telefone = $_POST['telefone'];
$serv_opcao1 = $_POST[serv-opcao1];
Spot the difference between working and not-working. Without quotes, PHP sees constant serv minus constant opaco1. Since both are undefined, they are treated as strings. And those strings doe not have any numerical value, so result of 0 - 0 is 0 and there is no $_POST[0]; If you have error reporting / logging on your server, you would see many notices about undefined constants / indexes. Error reporting and logs are first things to refer to when something does not work.
Moreover, php will not allow you to use some characters in request variables, automatically converting them to underscores, so try $_POST['serv_opcao1']; This should not be true for dashes, only spaces and dots.

Categories