Jump to content

PHPMAILER - Envio emails PHP


rocks

Recommended Posts

Boas ,

Estou a tentar fazer um site enviar email mas estou a ter alguns problemas.

Ao usar o gmail e enviar para o gmail nao tenho problemas nenhuns. Funciona tudo bem .

Ao usar office365 e enviar para office365 (rmmio@iscte-iul.pt) so funciona quando o email de quem envia é o mesmo de quem recebe.

 

Enviando de um mail "à toa" tenho o erro 

SMTP -> ERROR: DATA not accepted from server: 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 0.35250:0A006082, 1.36674:0A000000, 1.61250:00000000, 1.45378:02000000, 1.44866:3B1E0000, 1.36674:0E000000, 1.61250:00000000, 1.45378:401E0000, 1.44866:24020000, 16.55847:B10F0000, 17.43559:0000000024020000000000000000000000000000, 20.52176:140F488F1D00103100000000, 20.50032:140F488F8D17000000000000, 0.35180:140F488F, 255.23226:0A00
SMTP Error: Data not accepted.

 

Alguém consegue ajudar 

 

Desde ja Obrigado  

 

$email = 'rmmio@iscte-iul.pt';

$user = $user_check; 
$userID = $ID_USER;

$pri = $_POST['name']; 
$ult = $_POST['last']; 
$email_r = $email_user; 
$email_a = $_POST['email_A']; 
$num_a = $_POST['contacto_A']; 
$Description = $_POST['Description'];   

$Vai = "";
$Vai .= "User: ".$user."\n";
$Vai .= "User ID : ".$userID."\n";
$Vai .= "Nome: ".$pri." ".$ult."\n";
$Vai .= "Email registado: ".$email_r."\n";
$Vai .= "Email Alternativo: ".$email_a."\n";
$Vai .= "Numero Alternativo: ".$num_a."\n";
$Vai .= "Descrição: ".$Description."\n";


require_once("../phpmailer/class.phpmailer.php");

define('GUSER', 'rmmio@iscte-iul.pt');   

define('GPWD', '********');   

function smtpmailer($para, $de, $de_nome, $assunto, $corpo)

{

    global $error;

    $mail = new PHPMailer();

    $mail->CharSet = 'UTF-8';

    $mail->IsSMTP();        // Ativar SMTP

    $mail->SMTPDebug = 1;        // Debugar: 1 = erros e mensagens, 2 = mensagens apenas

    $mail->SMTPAuth = true;        // Autenticação ativada

    //$mail->SMTPSecure = 'tls';    // SSL REQUERIDO pelo GMail

    $mail->SMTPSecure = 'tls';    // SSL REQUERIDO pelo GMail

    $mail->Host = 'smtp.office365.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;

     }

 }

 if (smtpmailer($email, $email_r, $user, 'Novo Ticket', $Vai)) {

      echo "<script> alert('Novo registo criado com sucesso');</script>";

//echo "<script type=\"text/javascript\">document.location.href='form.php';</script>";

   //  exit();


 }
Link to comment
Share on other sites

13 horas atrás, rocks disse:

SMTP -> ERROR: DATA not accepted from server: 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 0.35250:0A006082, 1.36674:0A000000, 1.61250:00000000, 1.45378:02000000, 1.44866:3B1E0000, 1.36674:0E000000, 1.61250:00000000, 1.45378:401E0000, 1.44866:24020000, 16.55847:B10F0000, 17.43559:0000000024020000000000000000000000000000, 20.52176:140F488F1D00103100000000, 20.50032:140F488F8D17000000000000, 0.35180:140F488F, 255.23226:0A00
SMTP Error: Data not accepted.

Segundo esta explicação:

https://stackoverflow.com/questions/40016305/phpmailer-exceptionsendasdeniedexception-mapiexceptionsendasdenied

"Since july 2017 office 365 smtp does not allow using a "from" address other than your own (or what you're authenticated with), probably as an anti-spam measure"

Geralmente o "From" não costuma ser arbitrário... e deveria ser o mesmo utilizado na autenticação.

(nem sei porque o gmail o está a deixar fazer de outra forma... totalmente livre, sem restrições de que autentica e de quem envia..)

  • Vote 1
  • Thanks 1
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.