PHP Mailer - Undefined Method 'Subject'

Asked

Viewed 511 times

-1

send-contact.php

<?php
session_start();
$nome = $_POST["nome-contato"];
$email = $_POST["email-contato"];
$mensagem = $_POST["mensagem-contato"];

require_once("mailer/mail-autoloader.php");

$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "Necro145";

$mail->setFrom("[email protected]", "Murilo Henrique");
$mail->addAddress("[email protected]");
$mail->Subject("Email de contato da Nargloth Store");
$mail->msgHTML("<html> de: {$email} <br/> nome: {$nome} <br/><br/> {$mensagem}</html>");
$mail->AltBody = "de: {$email}\nnome: {$nome}\n\n{$mensagem}";

if ($mail->send()) {
    $_SESSION["success"] = "E-mail enviado com sucesso";
    header("Location: index.php");
}else{
    $_SESSION["error"] = "Devido a um erro, o seu email não foi enviado" . $mail->ErrorInfo;
    header("Location: contato.php");
}
die();

Error Log

( ! ) Fatal error: Call to undefined method PHPMailer::Subject() in C:\wamp64\www\phpI\envia-contato.php on line 20
Call Stack
#   Time    Memory  Function    Location
1   0.0000  249064  {main}( )   ...\envia-contato.php:0

I am trying to send a test form with PHP Mailer by localhost, but the above error is occurring.

  • 3

    Subject it’s not a method, use it like this $mail->Subject = "Email de contato da Nargloth Store";

1 answer

2


Subject is a class attribute PHPMailer. You can’t invoke it like you do with a method: $mail->Subject(). Instead, assign it the desired value, as follows: $mail->Subject = "Email de contato da Nargloth Store";.

If you still have questions, check the example of the official documentation: http://phpmailer.worxware.com/? pg=examplebsmtp

Browser other questions tagged

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