Send email using Cpanel and Phpmailer account

Asked

Viewed 1,395 times

6

I am trying to send an email using my Cpanel account and the phpmailler class but I am not succeeding , the code I am using is the same as the Phpmailler documentation, how should I proceed? , would anyone have a fucnional code to share? , thank you.

require_once(Yii::app()->basePath . '/components/PHPMailer-master/PHPMailerAutoload.php');
        $mail = new PHPMailer(true); // create a new object
        $mail->IsSMTP(); // enable SMTP
        $mail->SMTPDebug = 4; // debugging: 1 = errors and messages, 2 = messages only
        $mail->SMTPAuth = true; // authentication enabled
        $mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
        $mail->Host = "vps.meudominio.com.br";
        $mail->Port = 25;
        $mail->IsHTML(true);
        $mail->Username = "[email protected]";
        $mail->Password = "testeste";
        $mail->SetFrom("[email protected]");
        $mail->Subject = "Testesteaste";
        $mail->Body = "<body> <img  width='1px' height='1px' src='http://www.testesteste.com.br' /> <h3>hu3hu3h3u3hu</h3> TEEEESTE!!!!</body>";
        $mail->AddAddress("[email protected]");

        if(!$mail->Send())
        {
            echo "Mailer Error: " . $mail->ErrorInfo;
        }else{

        }
        exit;
  • 1

    First welcome to Stackoverflow in English, check out the Tour to take better advantage of the features it offers: http://answall.com/tour. Second, we need you to edit your question with the code you already have available and not working.

  • Are you returning any errors? I use the php file class.phpmailer.php and not PHPMailAutoload.php as in your case.

  • Apparently the door is wrong, 25 is for smtp without authentication for tls should be another. Try switching to 465

  • Try with port 587 using the same code posted.

1 answer

1

In my example you will have to leave the extension openssl habilitada, and port 465 should be open on your server.

Example of sending to Gmail:

<?php

require_once("PHPMailerAutoload.php");
define('GUSER', '[email protected]'); // <-- Insira aqui o seu email
define('GPWD', 'senhaqui');  // <-- Insira aqui a senha do seu email

$Vai = "Testando o envio de email, você pode excluir essa mensagem, apenas me avise que chegou com sucesso, obrigado.";

function smtpmailer($para, $de, $de_nome, $assunto, $corpo) {
   global $error;
   $mail = new PHPMailer();
   $mail->IsSMTP();  // Ativar SMTP
   $mail->SMTPDebug = 2;  // Debugar: 1 = erros e mensagens, 2 = mensagens apenas
   $mail->SMTPAuth = true;  // Autenticação ativada
   $mail->SMTPSecure = 'ssl'; // SSL REQUERIDO pelo GMail
   $mail->Host = 'smtp.gmail.com'; // SMTP utilizado
   $mail->Port = 465;    // A porta 465 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;
   }
}

// Insira abaixo o email que irá receber a mensagem, o email que irá enviar (o mesmo da variável GUSER),
// o nome do email que envia a mensagem, o Assunto da mensagem e por último a variável com o corpo do email.

if (smtpmailer('[email protected]', GUSER, 'Gabriel', 'Teste de envio', $Vai)) {
   echo 'seu imagem foi enviada';
}
if (!empty($error)) {
   echo $error;
}
?>
  • For Gmail I can send , only for Cpanel accounts that gives error, you know if it is some Cpanel configuration ? , already tested on some Cpanel account?

  • @talles_jp I never sent to Cpanel, these emails use some specific port ?

  • @talles_jp anyway enable debug to see which error message returns.

  • the error is timeout 300 seconds, nothing in particular.

  • arrow set_time_limit(0); at the beginning of the page and wait until another error occurs. you are sending attachments as well ?

  • SMTP Error: Could not connect to SMTP host.

  • @talles_jp sure that the openssl extension is enabled in your php.ini ?

  • Before continuing with SSL I suggest trying port 587. Port 25 is only currently used for communication between email servers.

Show 4 more comments

Browser other questions tagged

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