Jump to content

Problemas com phpmailer


EuricoFerreira

Recommended Posts

Eu não consigo que ele me envie uma mensagem para o endereço que esta guardado na session "$mail->AddAddress = ($_SESSION['email']);"

já testei "echo $_SESSION['email'] " para ver o que trazia e corresponde ao pretendido, mas no entanto aplicando as funções mail do php não funciona corretamente dando o seguinte erro " You must provide at least one recipient email address."

Edited by EuricoFerreira
Link to comment
Share on other sites

<?php
session_name('minha_sessao');
session_start();
$conn = mysql_connect('localhost','root','') or die(mysql_error());
$banco = mysql_select_db('pap') or die(mysql_error());
require("phpmailer/class.phpmailer.php");
$mensagem ="Testando o envio de email através de aplicações locais";
$msg = "<html>";
"<head></head>";
$msg .= "<body style=\"background-color:#fff;\" >";
$msg .= "<strong>MENSAGEM:</strong><br /><br />";
$msg .= $mensagem;
$msg .= "</body>";
$msg .= "</html>";
$mail = new PHPMailer();
$mail->Mailer	 = "smtp";
$mail->IsHTML(true);
$mail->CharSet	= "utf-8";
$mail->Host	   = "localhost";
$mail->Port	   = "25";				  
$mail->From	   = "admin@warehouse.pt";
$mail->FromName   = "Warehouse";
$utilizador  = $_SESSION['usernick'];
$sql = "SELECT * FROM cliente WHERE usernick = '$utilizador'";
$query = mysql_query($sql);
$row = mysql_fetch_assoc($query);
$endereco = settype($row['email'], 'string'); // estive a testar converter o valor recebido para string mas mesmo assim nao deu com nada
$mail->AddAddress = $endereco;
$mail->AddReplyTo("admin@warehouse.pt", $mail->FromName);
$mail->Subject	= "Assunto-da-mensagem";
$mail->Body	   = $msg;
if (!$mail->Send())
{
echo "Erro de envio: " . $mail->ErrorInfo;
}
else{
echo "Mensagem enviada com sucesso!";
}
?>
Edited by scorch
Adicionado Geshi. ;)
Link to comment
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.