Reputation: 569
So I'm working on this page: http://sitesdemo.mghospedagem.com/ivam-entregas/3/33209.html
And I'm facing a problem:
It uses SMTP to send data to an Email, but the only data that is being sent is from the fields "Nome" and "Email". The other fields "Endereço de Partida", "Endereço de Chegada" and "Detalhes do Serviço" are simply empty on submission.
Which php code is:
<?php
/*
* Vinteum Desenvolvimento
* [email protected]
*/
require_once('PHPMailer_5.2.1/class.phpmailer.php');
$nome = $_POST['nome'];
$email = $_POST['email'];
$msg = $_POST['txtDetalhes'];
$end1 = $_POST['1'];
$end2 = $_POST['txtEnderecoChegada'];
try {
$mail = new PHPMailer(true); //New instance, with exceptions enabled
$body .= "<h2>Pedido de orçamento para entrega</h2>";
$body .= "Nome: $nome <br>";
$body .= "E-mail: $email <br>";
$body .= "<br>";
$body .= "Mensagem: <br> $msg";
$body .= $msg;
$body .= "<br>";
$body .= "Endereço de partida: $end1 <br>";
$body .= "Endereço de chegada: $end2 <br>";
$body .= "<br>";
$body .= "----------------------------";
$body .= "<br>";
$body .= "Enviado em <b>".date("h:m:i d/m/Y")." por ".$_SERVER['REMOTE_ADDR']."</b>"; //Mostra data e Endereço IP
$body .= "<br>";
$body .= "----------------------------";
$mail->IsSMTP(); // tell the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 587; // set the SMTP server port, geralmente porta 25 ou 587
$mail->Host = "mail.xxxxxxx.com"; // SMTP server
$mail->Username = "[email protected]"; // SMTP server username
$mail->Password = "xxxxxxxxx"; // SMTP server password
//$mail->IsSendmail(); // tell the class to use Sendmail
$mail->AddReplyTo($email, $nome); //Responder para
$mail->From = $email; //De E-mail
$mail->FromName = $nome; //De Nome
$to = "[email protected]"; //Para
$mail->AddAddress($to);
$mail->Subject = "Orçamento para entrega"; //Assunto
$mail->AltBody = "Para ver essa mensagem utilize um cliente com suporte HTML!"; // optional, comment out and test
$mail->WordWrap = 80; // set word wrap
$mail->MsgHTML($body);
$mail->IsHTML(true); // send as HTML
$mail->Send();
echo 'Mensagem enviada com sucesso.<br><a href="33209.html">VOLTAR</a><br />';
echo $end1;
//retorno (html) devolvido para o ajax caso sucesso
} catch (phpmailerException $e) {
echo $e->errorMessage(); //retorno devolvido para o ajax caso erro
}
?>
Here is the HTML and Javascript code:
http://jsbin.com/qudumegihu/1/edit
Upvotes: 2
Views: 154
Reputation: 312
try this one. in your sendmailivam.php . Try to look Ravan's answer.
<?php
/*
* Vinteum Desenvolvimento
* [email protected]
*/
require_once('PHPMailer_5.2.1/class.phpmailer.php');
$nome = $_POST['nome'];
$email = $_POST['email'];
$msg = $_POST['msg'];
$end1 = $_POST['end1'];
$end2 = $_POST['end2'];
Upvotes: 0
Reputation: 6392
You are sending your data with:
var urlData = "&nome=" + nome + "&email=" + email + "&msg=" + msg + "&end1=" + end1 + "&end2=" + end2;
and then trying to grab txtDetalhes
and txtEnderecoChegada
from $_POST
, that doesn't exist. You should be using $_POST['end1']
and $_POST['end2]
instead.
A little tip: try using var_dump($_POST);
to see its contents. it's really helpful.
Upvotes: 1