Enviar email PHPMailer e gravar no banco (Envia mas não grava)
Pessoal estou usando PHPMailer para enviar email com dados do formulário e ao mesmo tempo gravar no mysql.
O email esta sendo enviado mas não esta gravando no banco, não sei onde estou errando segue meu código.
<?php include 'header.php'; ?>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="row">
<?php
date_default_timezone_set('Etc/UTC');
if(isset($_POST['btnsave']))
{
$id_cliente = $_POST['id_cliente'];
$produto = $_POST['produto'];
$medida = $_POST['medida'];
$msg = $_POST['msg'];
$qtd = $_POST['qtd'];
$aprovado = $_POST['aprovado'];
$status = $_POST['status'];
$data_orca = date('Y-m-d');
$imgFile = $_FILES['user_image']['name'];
$tmp_dir = $_FILES['user_image']['tmp_name'];
$imgSize = $_FILES['user_image']['size'];
if(empty($imgFile)){
$errMSG = "Please Select Image File.";
}
else
{
$upload_dir = 'imagens/orcamento/'; // upload directory
$imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
// valid image extensions
$valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
// rename uploading image
$userpic = rand(1000,1000000).".".$imgExt;
// allow valid image file formats
if(in_array($imgExt, $valid_extensions)){
// Check file size '5MB'
if($imgSize < 5000000) {
move_uploaded_file($tmp_dir,$upload_dir.$userpic);
}
else{
$errMSG = "Desculpe seu arquivo é muito grande.";
}
}
else{
$errMSG = "Desculpe, somente arquivos JPG, JPEG, PNG e GIF são aceitos.";
}
}
require_once('includes/init.php');
if(!isset($errMSG)){
$addv=$pdo->prepare("INSERT INTO orcamento (id_cliente, produto, medida, qtd, msg, aprovado, status, data_orca, img) VALUE(?,?,?,?,?,?,?,?,?)");
$addv->bindValue("1",$id_cliente);
$addv->bindValue("2",$produto);
$addv->bindValue("3",$medida);
$addv->bindValue("4",$qtd);
$addv->bindValue("5",$msg);
$addv->bindValue("6",$aprovado);
$addv->bindValue("7",$status);
$addv->bindValue("8",$data_orca);
$addv->bindValue("9",$userpic);
if($addv->execute())
{
$successMSG = "Orçamento enviado com sucesso...";
}
else
{
$errMSG = "Erro ao enviado Orçamento...";
}
}
$path_file = $upload_dir.$userpic;
///////////////////////////////////////////////////////////////////////////////////////////////
require 'phpmailer/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
$mail->CharSet = 'UTF-8';
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "smtp.uhserver.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 587;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "contato@xxxxx.com.br";
//Password to use for SMTP authentication
$mail->Password = "xxxxxx";
//Set who the message is to be sent from
$mail->setFrom('contato@xxxxx.com.br', 'xxxxx');
//Set an alternative reply-to address
$mail->addReplyTo('no-reply@xxxxx.com.br', 'xxxxx');
//Set who the message is to be sent to
$mail->addAddress('contato@xxxxx.com.br', 'xxxxx');
//Mantenha-o simples - não use HTML
$mail->isHTML(true);
$id = $_SESSION['id_do_produto'];
$add_pro = $pdo->prepare("SELECT * FROM produtos WHERE id = '$id' ORDER BY nome_produto ASC");
$add_pro->execute();
while($row=$add_pro->fetch(PDO::FETCH_ASSOC)){
extract($row);
$assunto = ''.$row['nome_produto'].'';
}
//Set the subject line
$mail->Subject = 'Solicitação de orcamento de: '.$assunto.'';
$mail->Body = '
<html bgcolor="#E6E6E6">
<table able width="60%" align="center" style="background-color:#ffffff; border:1px solid #cccccc;">
<tr style="background-color:#ffffff; border: 1px solid #cccccc;">
<td><a href="http://xxxxx.com.br" target="_blank"><img src="http://xxxxx.com.br/imagens/logo.png" width="300" height="80" /></a></td>
</tr>
<tr>
<td colspan="3"><hr / style="color:#cccccc;"></td>
</tr>
<tr style="background-color:#ffffff; border: 1px solid #cccccc;">
<td style="color:blue;"><strong> '.$assunto.'</strong></td>
</tr>
<tr>
<td colspan="3"><hr / style="color:#cccccc;"></td>
</tr>
<tr>
<td colspan="2">'.$msg.'</td>
</tr>
<tr>
<td colspan="3"><hr / style="color:#cccccc;"></td>
</tr>
<tr>
<td colspan="3" style="font-size:9px;">Roda pé do formulário</td>
</tr>
</table>
</html>
';
//$mail->AddAttachment($path_file);
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
//$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
//$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('examples/images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
//echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Mensagem Enviada!";
header('Location: index.php');
}
}
?>
<br/><br/>
<table class="table table-bordered table-responsive">
<form method="post" enctype="multipart/form-data" class="form-horizontal">
<tr>
<td><label class="control-label">Produto:</label></td>
<?php
$id = $_SESSION['id_do_produto'];
$add_pro = $pdo->prepare("SELECT * FROM produtos WHERE id = '$id' ORDER BY nome_produto ASC");
$add_pro->execute();
while($row=$add_pro->fetch(PDO::FETCH_ASSOC)){
extract($row);
echo'<td><input class="form-control" type="text" name="produto" value="'.$row['nome_produto'].'"/></td>';
}
?>
</tr>
<tr>
<td><label class="control-label">Cliente:</label></td>
<td><input class="form-control" type="text" name="" value="<?php echo $_SESSION['c_nome'] ?>"/>
<input class="form-control" type="hidden" name="id_cliente" value="<?php echo $_SESSION['c_id'] ?>"/></td>
</tr>
<tr>
<td><label class="control-label">Medida: <i style="font-size: 11px">Altura X Largura</i></label></td>
<td><input class="form-control" type="text" name="medida" placeholder="0,00 x 0,00" /></td>
</tr>
<tr>
<td><label class="control-label">Quantidde:</label></td>
<td><input class="form-control" type="text" name="qtd" /></td>
</tr>
<tr>
<td><label class="control-label">Mensagem.</label></td>
<td><textarea class="form-control" type="text" name="msg" rows="3" placeholder="Mensagem"></textarea></td>
</tr>
<input class="form-control" type="hidden" name="aprovado" value="Não" />
<input class="form-control" type="hidden" name="status" value="Aberto" />
<tr>
<td><label class="control-label">Envie seu Layout.</label></td>
<td><input class="input-group" type="file" name="user_image" accept="image/*" /></td>
</tr>
<tr>
<td colspan="2" style="text-align:center; padding: 30px;"><button type="submit" name="btnsave" class="btn btn-primary">
<span class="glyphicon glyphicon-save"></span> Enviar Orçamento
</button>
</td>
</tr>
</form>
</table>
</div><!-- /.row -->
</div><!-- /.col-md-12 -->
</div><!-- /.row -->
</div><!-- /.container -->
<?php include 'footer.php'; ?>Discussão (1)
Carregando comentários...