Phpmailer does not send email

Asked

Viewed 966 times

3

I have a problem with the PHP Mailer class, and I have an even bigger problem, because it is an email that is sent when there is some change in the status of the transaction, so I can’t debug this page, because the POST comes from an API.

Everything is working, update in the table and etc, but the email is not sent.

Follows the code

date_default_timezone_set('America/Sao_Paulo');

require_once 'phpmailer/PHPMailerAutoload.php';

$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = "smtp.xxx.com";
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = "xx";
$mail->Password = "xx";
$mail->setFrom('noreply@xxx', 'xxx rds');
$mail->addReplyTo('[email protected]', 'xxx rds Store');
$mail->AddAddress($_POST['customer_email'], $_POST['customer_name']);
$mail->AddBCC('[email protected]', 'Admin xxx rds');
$mail->Subject = 'Notificação de compra no site da xxx rds';
        $mail->Body = '<!DOCTYPE html>
                    <html>
                    <head>
                    <meta http-equiv="content-type" content="text-html; charset=utf-8" />
                    </head>
                    <body>';
        $mail->Body .= '<h1>Obrigado pela sua compra</h1>';
        $mail->Body .= '<h2>Recebemos seu pedido, e seu pagamento está sendo processado.</h2>';
        $mail->Body .= '<p>Prezado '.$_POST['customer_name'].', recebemos na data '.$_POST['created_date'].' a notificação da sua compra no nosso site.</p>';
        $mail->Body .= '<p>Produto / Quantidade:';
        $products = json_decode($row['order_products']);
        foreach($products as $product){
        $mail->Body .= $product->name.' / '. $product->qty;
        }
        $mail->Body .= '</p>';
        $mail->Body .= '<p>No valor de R$'.formata_preco($row['order_products_price']).'</p>';
        if(!$details_ship == NULL){
        $mail->Body .= '<p>Os dados para entrega são:'.$details_ship.'</p>';
        $mail->Body .= '<p>Com valor de frete de R$'.formata_preco($price_ship).'</p>';
        $mail->Body .= '<p>Quando seu produto for postado, você receberá um E-Mail com o código de rastreamento do mesmo</p>';
        }
        $mail->Body .= '<p>Assim que seu pagamento for confirmado, enviaremos outro E-Mail com novas informações</p>';
        $mail->Body .= '<p>Para mais detalhes e informações sobre essa transação, <a href="http://xxxx/'.$order_number.'">clique aqui</a></p>';
        $mail->Body .= '<p>Ou copie esse link para seu navegador: <a href="http://xxxx/'.$order_number.'">http://xxxx/'.$order_number.'</a></p>';
        $mail->Body .= '<p>Para esclarecimento ou qualquer dúvida, entre em contato conosco pelo E-Mail <a href="mailto:[email protected]">[email protected]</a> ou entre em contato direto com o administrador <a href="mailto:[email protected]">[email protected]</a></p>';
        $mail->Body .= '<p>A xxx rds agradece a sua compra</p>';
        $mail->Body .= '</body>
                 </html>';
$mail->AltBody = 'Para conseguir essa e-mail corretamente, use um visualizador de e-mail com suporte a HTML';
$sent = $mail->Send();

Thanks in advance

  • Maybe my help is not useful, but you had already "uncommented" the part of Openssl in the PHP.ini file right?

1 answer

2


I have an email sent with Phpmailer that is all right, I will post there you try to change to see if it is right

$mail = new PHPMailer();

$mail->SMTPDebug = 1;
$mail->Timeout = 60;
$mail->IsHTML(true);
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->From = $email;
$mail->FromName = $_GET['nomeFilial'];
$mail->Username = $usuario;
$mail->Host = $host;
$mail->Password = $senha;
$mail->Port = $porta;
$mail->Subject = "CT-e(s) emitido(s)";

$mail->AddEmbeddedImage('../../modelo/logoEmpresa.jpg', 'logoEmpresa');

if ($_GET['geraPDF'] == "S") {
    $mail->AddAttachment($pdf);
}

if ($_GET['geraXML'] == "S") {
    $mail->AddAttachment($xml);
}

$mail->AddAddress("[email protected]");
$mail->Body = $html;

if ($mail->Send()) {

    error_log("Email enviado");

    echo "Email enviado com sucesso";
} else {

    error_log("Erro no envio do email");
    error_log($mail->ErrorInfo);

    echo "Erro do servidor: " . $mail->ErrorInfo;
}

Try to add the error log as I did this can help to find the problem, any doubt feel free to ask in the area of comnents

  • error_log goes where Cristian? pro log PHP?

  • 1

    is a function of php http://php.net/manual/en/function.error-log.php

  • thank you very much Cristian. I will debug now without problems hehe

Browser other questions tagged

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