Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Lady01

Erro ao tentar enviar email com phpmailer

Recommended Posts

Estou tentando enviar e-mail com o phpmailer e estou tendo o seguinte erro:

 

Could not instantiate mail function

 

Eis o codigo:

 

[inline]

<?php

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

$mail="leidianeborges21@gmail.com";

$email = new PHPMailer();
$email->isMail();
$email->SetLanguage("br");
$email->SMTPDebug = 1;
$email->From = $mail;
$email->AddAddress($mail);
$email->IsHTML(true);
$email->Subject = "Orcamento";
$email->Sender = "leidianeborges21@gmail.com";
$email->Body = "teste";
$UPLOAD = $_FILES['txtUpload'];
$quantos=count($UPLOAD['name']);
#var_dump($email);
for($j=0; $j<$quantos; $j++)
{
if (move_uploaded_file($UPLOAD['tmp_name'][$j],'upload/'.$UPLOAD['name'][$j]))
{
$email->addAttachment('upload/'.$UPLOAD['name'][$j]);
}
}
var_dump($email);
if ( $email->Send() )
{
echo "foi";
}
else
{
echo "nao foi".$email->ErrorInfo;;
}

?>

[/inline]

 

 

Já pesquisei de tudo, já tentei de tudo, com autenticação, agora sem. Não sei mais o que fazer.

Alguém pode me ajudar?

Att

Compartilhar este post


Link para o post
Compartilhar em outros sites

Olá,

 

Mesmo com autenticação não funcionou?

 

Existe um tópico semelhante:

http://forum.imasters.com.br/topic/334698-resolvidophpmailer-gmail/page-3

no qual o problema foi resolvido instalando a extensão openssl no php

Compartilhar este post


Link para o post
Compartilhar em outros sites

Isso, nem autenticado.

O ssl já está habilitado.

Esse erro dá tanto local quanto remoto.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tentei agora e não deu certo também.

Windows em ambos.

Tô printando o objeto $email na tela, agora mudou o erro com esse isSMTP():

object(PHPMailer)#1 (53) { ["Priority"]=> int(3) ["CharSet"]=> string(10) "iso-8859-1" ["ContentType"]=> string(9) "text/html" ["Encoding"]=> string(4) "8bit" ["ErrorInfo"]=> string(0) "" ["From"]=> string(26) "leidianeborges21@gmail.com" ["FromName"]=> string(9) "Root User" ["Sender"]=> string(26) "leidianeborges21@gmail.com" ["Subject"]=> string(9) "Orcamento" ["Body"]=> string(5) "teste" ["AltBody"]=> string(0) "" ["WordWrap"]=> int(0) ["Mailer"]=> string(4) "smtp" ["Sendmail"]=> string(18) "/usr/sbin/sendmail" ["PluginDir"]=> string(0) "" ["ConfirmReadingTo"]=> string(0) "" ["Hostname"]=> string(0) "" ["MessageID"]=> string(0) "" ["Host"]=> string(14) "smtp.gmail.com" ["Port"]=> int(465) ["Helo"]=> string(0) "" ["SMTPSecure"]=> string(0) "" ["SMTPAuth"]=> bool(false) ["Username"]=> string(0) "" ["Password"]=> string(0) "" ["Timeout"]=> int(10) ["SMTPDebug"]=> int(1) ["SMTPKeepAlive"]=> bool(false) ["SingleTo"]=> bool(false) ["SingleToArray"]=> array(0) { } ["LE"]=> string(1) " " ["DKIM_selector"]=> string(9) "phpmailer" ["DKIM_identity"]=> string(0) "" ["DKIM_domain"]=> string(0) "" ["DKIM_private"]=> string(0) "" ["action_function"]=> string(0) "" ["Version"]=> string(3) "5.1" ["smtp":"PHPMailer":private]=> NULL ["to":"PHPMailer":private]=> array(1) { [0]=> array(2) { [0]=> string(26) "leidianeborges21@gmail.com" [1]=> string(0) "" } } ["cc":"PHPMailer":private]=> array(0) { } ["bcc":"PHPMailer":private]=> array(0) { } ["ReplyTo":"PHPMailer":private]=> array(0) { } ["all_recipients":"PHPMailer":private]=> array(1) { ["leidianeborges21@gmail.com"]=> bool(true) } ["attachment":"PHPMailer":private]=> array(0) { } ["CustomHeader":"PHPMailer":private]=> array(0) { } ["message_type":"PHPMailer":private]=> string(0) "" ["boundary":"PHPMailer":private]=> array(0) { } ["language":protected]=> array(17) { ["provide_address"]=> string(54) "You must provide at least one recipient email address." ["mailer_not_supported"]=> string(25) " mailer is not supported." ["execute"]=> string(19) "Could not execute: " ["instantiate"]=> string(36) "Could not instantiate mail function." ["authenticate"]=> string(35) "SMTP Error: Could not authenticate." ["from_failed"]=> string(35) "The following From address failed: " ["recipients_failed"]=> string(45) "SMTP Error: The following recipients failed: " ["data_not_accepted"]=> string(30) "SMTP Error: Data not accepted." ["connect_host"]=> string(43) "SMTP Error: Could not connect to SMTP host." ["file_access"]=> string(23) "Could not access file: " ["file_open"]=> string(33) "File Error: Could not open file: " ["encoding"]=> string(18) "Unknown encoding: " ["signing"]=> string(15) "Signing Error: " ["smtp_error"]=> string(19) "SMTP server error: " ["empty_message"]=> string(18) "Message body empty" ["invalid_address"]=> string(15) "Invalid address" ["variable_set"]=> string(30) "Cannot set or reset variable: " } ["error_count":"PHPMailer":private]=> int(0) ["sign_cert_file":"PHPMailer":private]=> string(0) "" ["sign_key_file":"PHPMailer":private]=> string(0) "" ["sign_key_pass":"PHPMailer":private]=> string(0) "" ["exceptions":"PHPMailer":private]=> bool(false) } SMTP -> ERROR: EHLO not accepted from server:
SMTP -> ERROR: HELO not accepted from server:
SMTP -> NOTICE: EOF caught while checking if connectedThe following From address failed: leidianeborges21@gmail.com nao foiThe following From address failed: leidianeborges21@gmail.com

 

Será que dá pra ter uma pista melhor?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Evite localmente pois tera que mexer em muita configuração para funcionar,

 

pelo que vi você esta tentando enviar usando email do gmail, o gmail é obrigatorio o envio autenticado.

 

eu nunca tinha visto essa mensagem de erro, siga essas dicas veja se resolve

 

https://www.acyba.com/acymailing/246-could-not-instantiate-mail-function.html

Compartilhar este post


Link para o post
Compartilhar em outros sites

Você precisa configurar o objeto com suas informações SMTP.

//Informa que será utilizado o SMTP para envio do e-mail  
$mail->IsSMTP();  
  
//Informa que a conexão com o SMTP será autênticado  
$mail->SMTPAuth   = true;  
  
//Configura a segurança para SSL  
$mail->SMTPSecure = "ssl";  
  
//Informa a porta de conexão do GAMIL  
$mail->Port       = 465;  
  
//Informa o HOST do GMAIL  
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server  
  
//Usuário para autênticação do SMTP  
$mail->Username =   "seuemailgmail@gmail.com";  
  
//Senha para autênticação do SMTP  
$mail->Password =   "123456";  

Fonte: http://www.ogenial.com.br/phpmailer-gmail

 

É o seu mesmo login do gmail, talvez você receba um alerta na sua conta, mas basta marcar como aplicação confiável.

 

 

Talvez não esteja vendo todos os erros ligue a flag SMTPDebug para 2.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Então, pra mim é mais importante que rode remotamente mesmo.

Alterei o código com as dicas de vocês, funcionou local, mas não remotamente =/

Ficou assim:[inline]

$mail="leidianeborges21@gmail.com";
$email = new PHPMailer();
$email->isMail();
$email->isSMTP();
//Informa que a conexão com o SMTP será autênticado
$email->SMTPAuth = true;
//Configura a segurança para SSL
$email->SMTPSecure = "ssl";
//Informa a porta de conexão do GAMIL
$email->Port = 465;
//Informa o HOST do GMAIL
$email->Host = "smtp.gmail.com";
$email->Username = "leidianeborges21@gmail.com";
//Senha para autênticação do SMTP
$email->Password = "*********";
$email->SetLanguage("br");
$email->SMTPDebug = 2;
$email->From = $email->Username;
$email->AddAddress($mail);
$email->AddCC($mail, 'Ciclano');
$email->IsHTML(true);
$email->Subject = "Orcamento";
//$email->Sender = "leidianeborges21@gmail.com";
$email->Body = "teste";
$email->AltBody = $email->Body;
$UPLOAD = $_FILES['txtUpload'];
$quantos=count($UPLOAD['name']);
for($j=0; $j<$quantos; $j++)
{
if (move_uploaded_file($UPLOAD['tmp_name'][$j],'upload/'.$UPLOAD['name'][$j]))
{
$email->addAttachment('upload/'.$UPLOAD['name'][$j]);
}
}
var_dump($email);
if ( $email->Send() )
{
echo "foi";
}
else
{
echo "nao foi".$email->ErrorInfo;;
}

[/inline]

o print do objeto e o erro:
object(PHPMailer)#1 (53) { ["Priority"]=> int(3) ["CharSet"]=> string(10) "iso-8859-1" ["ContentType"]=> string(9) "text/html" ["Encoding"]=> string(4) "8bit" ["ErrorInfo"]=> string(0) "" ["From"]=> string(26) "leidianeborges21@gmail.com" ["FromName"]=> string(9) "Root User" ["Sender"]=> string(0) "" ["Subject"]=> string(9) "Orcamento" ["Body"]=> string(5) "teste" ["AltBody"]=> string(5) "teste" ["WordWrap"]=> int(0) ["Mailer"]=> string(4) "smtp" ["Sendmail"]=> string(18) "/usr/sbin/sendmail" ["PluginDir"]=> string(0) "" ["ConfirmReadingTo"]=> string(0) "" ["Hostname"]=> string(0) "" ["MessageID"]=> string(0) "" ["Host"]=> string(14) "smtp.gmail.com" ["Port"]=> int(465) ["Helo"]=> string(0) "" ["SMTPSecure"]=> string(3) "ssl" ["SMTPAuth"]=> bool(true) ["Username"]=> string(26) "leidianeborges21@gmail.com" ["Password"]=> string(8) "*********" ["Timeout"]=> int(10) ["SMTPDebug"]=> int(2) ["SMTPKeepAlive"]=> bool(false) ["SingleTo"]=> bool(false) ["SingleToArray"]=> array(0) { } ["LE"]=> string(1) " " ["DKIM_selector"]=> string(9) "phpmailer" ["DKIM_identity"]=> string(0) "" ["DKIM_domain"]=> string(0) "" ["DKIM_private"]=> string(0) "" ["action_function"]=> string(0) "" ["Version"]=> string(3) "5.1" ["smtp":"PHPMailer":private]=> NULL ["to":"PHPMailer":private]=> array(1) { [0]=> array(2) { [0]=> string(26) "leidianeborges21@gmail.com" [1]=> string(0) "" } } ["cc":"PHPMailer":private]=> array(0) { } ["bcc":"PHPMailer":private]=> array(0) { } ["ReplyTo":"PHPMailer":private]=> array(0) { } ["all_recipients":"PHPMailer":private]=> array(1) { ["leidianeborges21@gmail.com"]=> bool(true) } ["attachment":"PHPMailer":private]=> array(0) { } ["CustomHeader":"PHPMailer":private]=> array(0) { } ["message_type":"PHPMailer":private]=> string(0) "" ["boundary":"PHPMailer":private]=> array(0) { } ["language":protected]=> array(17) { ["provide_address"]=> string(54) "You must provide at least one recipient email address." ["mailer_not_supported"]=> string(25) " mailer is not supported." ["execute"]=> string(19) "Could not execute: " ["instantiate"]=> string(36) "Could not instantiate mail function." ["authenticate"]=> string(35) "SMTP Error: Could not authenticate." ["from_failed"]=> string(35) "The following From address failed: " ["recipients_failed"]=> string(45) "SMTP Error: The following recipients failed: " ["data_not_accepted"]=> string(30) "SMTP Error: Data not accepted." ["connect_host"]=> string(43) "SMTP Error: Could not connect to SMTP host." ["file_access"]=> string(23) "Could not access file: " ["file_open"]=> string(33) "File Error: Could not open file: " ["encoding"]=> string(18) "Unknown encoding: " ["signing"]=> string(15) "Signing Error: " ["smtp_error"]=> string(19) "SMTP server error: " ["empty_message"]=> string(18) "Message body empty" ["invalid_address"]=> string(15) "Invalid address" ["variable_set"]=> string(30) "Cannot set or reset variable: " } ["error_count":"PHPMailer":private]=> int(0) ["sign_cert_file":"PHPMailer":private]=> string(0) "" ["sign_key_file":"PHPMailer":private]=> string(0) "" ["sign_key_pass":"PHPMailer":private]=> string(0) "" ["exceptions":"PHPMailer":private]=> bool(false) } SMTP -> FROM SERVER:220 mx.google.com ESMTP d49sm3836930qge.45 - gsmtp
SMTP -> FROM SERVER: 250-mx.google.com at your service, [177.22.175.170] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8
SMTP -> ERROR: Password not accepted from server: 534-5.7.14 Please log in via your web browser and then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 d49sm3836930qge.45 - gsmtp
SMTP -> FROM SERVER:250 2.1.5 Flushed d49sm3836930qge.45 - gsmtp
SMTP Error: Could not authenticate. nao foiSMTP Error: Could not authenticate.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Observe essa linha do erro

SMTP -> ERROR: Password not accepted from server: 534-5.7.14 Please log in via your web browser and then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.goog...py?answer=78754 d49sm3836930qge.45 - gsmtp 
SMTP -> FROM SERVER:250 2.1.5 Flushed d49sm3836930qge.45 - gsmtp 
SMTP Error: Could not authenticate. nao foiSMTP Error: Could not authenticate.

sua autenticação esta correta ?

login e senha e porta

 

tente usar a porta do gmail se não funcionar Tente usar a porta 587, se não funcionar baixe novamente o phpmail as vezes corrompeu algum arquivo

Compartilhar este post


Link para o post
Compartilhar em outros sites

A autenticação está correta.

Com a porta 465 funciona só localmente.

Com a 587 não funciona nem localmente, nem remotamente =/

SInceramente, tô pensando em desistir do envio de e-mail e trabalhar com armazenamento em banco de dados. Porque eu já não sei mais o que fazer com esses erros.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Antes de mais nada, veja com o host se a porta está desbloqueada... andei tendo dores de cabeças com portas padrão bloqueadas na hostgator, depois de muito quebrar a cabeça vi que o problema não era o script e sim a infra do host.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Quando não se consegue acessar o conteúdo de uma url com https na frente, é porque o ssl não está habilitado. Certo?

Porque o suporte da hospedagem disse que o ssl já estava instalado, mas simplesmente me mandou um certificado com o formato .crt sem nenhuma instrução. Acredito, com base no que foi dito aqui e com base no que o suporte não disse, que o que falta para funcionar é a instalação desse certificado. Será isso, gente?

Porque no meu trabalho eu desenvolvi um script parecido com autenticação em 5 minutos e funcionou logo de cara. E já com esse, eu estou com esse problema todo.

Compartilhar este post


Link para o post
Compartilhar em outros sites

SSL não influencia no envio de emails, você só vai usar o SSL em páginas de login e senha, afim de criptografar as informações do usuario assim impedindo que crackers pegue a senha do mesmo.

 

No seu caso pergunte para o pessoal que fornece a hospedagem se as portas 587 e 465 estão aberta, diga que você esta tentando enviar emails autenticados com o gmail usando o plugin PHPMAIL e não esta conseguindo.

 

Diga que você ja fez teste e funcionou o seu script localmente mas remotamente no servidor não funciona.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.