Failed PHP Code: Indicates Sent Email But Sends Nothing

Asked

Viewed 554 times

0

I want to complete this code to send a file whenever a given page opens.

<?php

// Incluir a classe no teu ficheiro
require_once 'PHPMailerAutoload.php';
require_once 'class.phpmailer.php';
require_once 'class.smtp.php';

// Instanciar a classe para envio de email
$mail = new PHPMailer(true);

// Vamos tentar realizar o envio
try {

    // Remetente
    $mail->AddReplyTo('[email protected]', 'Meu Nome');
    $mail->SetFrom('[email protected]', 'Meu Nome');



    // Destinatário
    $mail->AddAddress('[email protected]', 'Destinatário');

    // Assunto
    $mail->Subject = 'Segue ficheiro anexo com XPTO';

    // Mensagem para clientes de email sem suporte a HTML
    $mail->AltBody = 'Em anexo o ficheiro com XPTO.';

    // Mensagem para clientes de email com suporte a HTML
    $mail->MsgHTML('<p>Em anexo o ficheiro com XPTO.</p>');

    // Adicionar anexo
    $caminho = 'C:/xampp/htdocs/envio_de_arquivo_automatico/PHP_ENVIAR_ARQUIVO_POR_EMAIL/PHPMAILER/PHPMailer-master/PHPMailer-master/';
    $ficheiro = 'Documento2.docx';

    $mail->AddAttachment($caminho.$ficheiro);

    // Enviar email
    $mail->Send();

    echo "Mensagem enviada!";
}
catch (phpmailerException $e) {
    // Mensagens de erro do PHPMailer
    echo $e->errorMessage();
}
catch (Exception $e) {
    // Outras mensagens de erro
    echo $e->getMessage();
}

?>
  • 1

    Email is sent and attachment does not appear? or email is not sent? Use this``` ` bar to specify the folders.

  • Email does not get sent. And by changing / by error: syntax error, unexpected 'Document2'

  • I don’t know if it makes a difference but I’m running on LOCALHOST.

  • 1

    Email server is configured? maybe that question help

  • I believe so, but I keep checking if I haven’t forgotten anything.

  • 1

    Other than that only the same bar, either you use double quotes or it escapes so C:\\pasta\\arquivo.txt

  • Thanks for the help but it hasn’t worked out yet.

  • If there is no error message anywhere in PHP (including Apache error logs), it is likely that your SMTP server is misconfigured. I agree with @rray on the /: you must replace them with \\, because it is on the Windows platform.

  • Fought people I got, actually I changed the code a little.

  • $host = 'smtp.live.com'; $username = '[email protected]'; $password = 'PASSWORD'; $port = 587; $Secure = 'tls'; $from = $username; $fromName = 'My Name';

  • $mail->From = $from; $mail->Fromname = $fromName; $mail->isSMTP(); $mail->Host = $host; $mail->Smtpauth = true; $mail->Username = $username; $mail->Password = $password; $mail->Port = $port; $mail->Smtpsecure = $Secure;

  • // Add attachment $path = 'C: xampp htdocs envio_de_arquivo_automatico PHP_ENVIAR_ARQUIVO_POR_EMAIL PHPMAILER Phpmailer-master Phpmailer-master ; $file = 'Document2.docx';

Show 7 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.