0
I need the information from my form to be sent to my email I’m doing at php but it doesn’t work follow my code:
<form action="email.php" method="post">
<label for="Nome">nome:</label>
<input type="text" name="Nome" size="35" /><br>
<label for="Email">E-mail:</label>
<input type="text" name="Email" size="35" /><br>
<label for="Fone">Telefone:</label>
<input type="text" name="Fone" size="35" /><br>
<label for="Mensagem">Mensagem:</label>
<textarea name="Mensagem" rows="8" cols="40"></textarea><br>
<input type="submit" name="Enviar" value="Enviar" />
</form>
my code in php is in a separate file from my code:
<?php
$Nome = $_POST["Nome"]; // Pega o valor do campo Nome
$Fone = $_POST["Fone"]; // Pega o valor do campo Telefone
$Email = $_POST["Email"]; // Pega o valor do campo Email
$Mensagem = $_POST["Mensagem"]; // Pega os valores do campo Mensagem
// Variável que junta os valores acima e monta o corpo do email
$Vai = "Nome: $Nome\n\nE-mail: $Email\n\nTelefone: $Fone\n\nMensagem: $Mensagem\n";
require_once("phpmailer/class.phpmailer.php");
define('GUSER', '[email protected]'); // <-- Insira aqui o seu GMail
define('GPWD', 'lalala123'); // <-- Insira aqui a senha do seu GMail
function smtpmailer($para, $de, $de_nome, $assunto, $corpo) {
global $error;
$mail = new PHPMailer();
$mail->IsSMTP(); // Ativar SMTP
$mail->SMTPDebug = 2; // Debugar: 1 = erros e mensagens, 2 = mensagens apenas
$mail->SMTPAuth = true; // Autenticação ativada
$mail->SMTPSecure = 'ssl'; // SSL REQUERIDO pelo GMail
$mail->Host = 'smtp.gmail.com'; // SMTP utilizado
$mail->Port = 587; // A porta 587 deverá estar aberta em seu servidor
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($de, $de_nome);
$mail->Subject = $assunto;
$mail->Body = $corpo;
$mail->AddAddress($para);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Mensagem enviada!';
return true;
}
}
// Insira abaixo o email que irá receber a mensagem, o email que irá enviar (o mesmo da variável GUSER),
if (smtpmailer('[email protected]', '[email protected]', 'felipe', 'Assunto do Email', $Vai)) {
Header("location:http://www.dominio.com.br/obrigado.html"); // Redireciona para uma página de obrigado.
}
if (!empty($error)) echo $error;
?>
run the project and gave this error:
Instead of just using
\n
, use\r\n
as line break.– stderr
@qmechanik friend so nothing happened i lico in the starting button and he redirects me to a page where has hi my php code on the screen and does not send
– Felipe Henrique
You have the application in local environment?
– Michel Simões
ss site I haven’t even hosted my site yet and I’m very novice in php started today say asim rsrsrsrs
– Felipe Henrique
When you submit the form, does it go to the . php page that contains the code and displays it? So the problem is on your web server. Make sure you have installed PHP and Apache correctly.
– Marcelo de Andrade
Take a look at this topic: http://stackoverflow.com/questions/4532486/failed-to-connect-to-mailserver-at-localhost-port-25 OBS: It is not easier for you to use Phpmailer or Swiftmailer?
– Rafael Withoeft
Put your
$mail->SMTPDebug = 0;
with the value 2.$mail->SMTPDebug = 2;
and look what happened.– Rafael Withoeft
friend gave a different error I will edit the post and put the error that gave
– Felipe Henrique
Take a look at the gmail configuration table: https://support.google.com/a/answer/176600?hl=pt-BR according to this documentation port 587 uses TLS, try switching to port 465. (I hope that’s right...) or changes your
SMTPSecure
fortls
– Rafael Withoeft
Hi, go to: https://www.google.com/settings/security/lesssecureapps and cancel the option:
Ativar
. From a time until you receive an email from Google saying that security has been disabled and try running the script. :$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
– dHEKU
ready I’ll wait now and see what’s taking so long ???
– Felipe Henrique
obrigadooooo rapaziadaaaa amo vcsssssssssssss uhuuuuuu
– Felipe Henrique