php Fatal error: Cannot use Object PHPMAILER of type as array

Asked

Viewed 155 times

-4

I’m having trouble sending an email.

Code

<?php
#inclui a classe PHPMAILER
include("phpmailer/class.phpmailer.php"); //pasta em que a classe se encontra
#instancia o objeto
$mail = new PHPMailer();
#enviar via SMTP
$mail->IsSMTP();
#seu servidor smtp / dominio no meu caso "mail" mas pode mudar verifique o seu!
$mail->Host = " [email protected] ";
#habilita smtp autenticado
$mail['smtp_port'] = 465;
$mail->SMTPAuth = true;
#usuário deste servidor smtp. Aqui esta a solucao
$mail->Username = "[email protected]";
$mail->Password = "teste"; // senha
#email utilizado para o envio, pode ser o mesmo de username
$mail->From = "[email protected]";
$mail->FromName = " [email protected] ";

#Enderecos que devem receber a mensagem
$mail->AddAddress("[email protected]","Contato");
#$mail->AddAddress("[email protected]","Contato");
#wrap seta o tamanhdo do texto por linha
$mail->WordWrap = 50;
#anexando arquivos no email (supondo estar no mesmo diretorio)
// $mail->AddAttachment("arquivo.zip");
// $mail->AddAttachment("foto.jpg");
$mail->IsHTML(true); //enviar em HTML

#recebendo os dados do formulario
if(isset($_POST['nome'])){
$nome    = $_POST['nome'];
$email    = $_POST['email'];
$como = $_POST['como'];
$ddd  = $_POST['ddd'];
$telefone = $_POST['telefone'];
#informando a quem devemos responder. o mail inserido no formulario
$mail->AddReplyTo("$email","$nome");
#criando o codigo html para enviar no email, voce pode utilizar qualquer tag html
$msg  = "Contato Site";
$msg .= " Nome: $nome\n";
$msg .= " E-mail: $email\n";
$msg .= " Como nos conheceu?: $como \n";
$msg .= " ddd: $ddd \n";
$msg .= " telefone: $telefone \n";
}

$mail->Subject = "ASSUNTO DO EMAIL";
#adicionando o html no corpo do email
$mail->Body = $msg;
#enviando e retornando o status de envio
$mail->send();
if(!$mail->Send())
{
echo "houve um erro ao  enviar o email! erro: $mail->ErrorInfo";
#$mail->ErrorInfo informa onde ocorreu o erro, o uso opcional
exit;
}
echo "Mensagem enviada ok";
?>

Error

php Fatal error: Cannot use Object PHPMAILER of type as array

  • I suspect the mistake is here $mail['smtp_port'] = 465, as the error message suggests this should be accessed as an object and not an array, so the correct one would be: $mail->smtp_port = 465

  • If you change this you cannot access the [email protected] email

  • appears these errors Warning: fsockopen() [Function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/XYZTERSA/public_html/class.smtp.php on line 90 Warning: fsockopen() [Function.fsockopen]: Unable to connect to [email protected] :465 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /home/Xyztersaa/public_html/class.smtp.php on line 90

  • Yes it is possible! http://phpmailer.worxware.com/? pg=examplebgmail

  • Warning: fsockopen() [Function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/XYRSA/public_html/class.smtp.php on line 90 Warning: fsockopen() [Function.fsockopen]: Unable to connect to [email protected] :465 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /home/TEA/public_html/class.smtp.php on line 90 there was an error sending the email! error: SMTP Error: Could not connect to SMTP host.

  • 1

    A tip, remember to add a context of the problem by adding a new topic, example :"I’m having trouble sending an email." this will contribute both to the personnel understanding their problem and help in the future those who do a research seeking an answer to the same problem.

Show 1 more comment

1 answer

1

Browser other questions tagged

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