O
O
Olga2018-11-27 17:22:47
PHP
Olga, 2018-11-27 17:22:47

How to solve "PHP Fatal error: Uncaught Error: Call to a member function isSMTP() on string /form/mail.php:24\nStack trace:\n#0 {main}\n thrown" error?

Good evening!
I am sending requests from the site via SMTP (PHPMailer), but the following error is displayed in the logs:

PHP Fatal error: Uncaught Error: Call to a member function isSMTP() on string in /public_html/form/mail.php:24\nStack trace:\n#0 {main}\n thrown in /public_html/form/mail. php on line 24

Here is the mail.php itself:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require_once('Exception.php');
require_once('PHPMailer.php');
require_once('SMTP.php');
$mail = new PHPMailer();
$mail->CharSet = 'utf-8';



$name = $_POST["name"];
$phone = $_POST["phone"];
$mail = $_POST["mail"];
$city = $_POST["city"];  

$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.yandex.ru';  																							// Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '[email protected]'; // Ваш логин от почты с которой будут отправляться письма
$mail->Password = 'xxx'; // Ваш пароль от почты с которой будут отправляться письма
$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to / этот порт может отличаться у других провайдеров

$mail->setFrom('[email protected]'); // от кого будет уходить письмо?
$mail->addAddress('[email protected]');     // Кому будет уходить письмо 
//$mail->addAddress('[email protected]');               // Name is optional
//$mail->addReplyTo('[email protected]', 'Information');
//$mail->addCC('[email protected]');
//$mail->addBCC('[email protected]');
//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Новая заявка со страницы ' ;
$mail->Body    = '' .$name . ' оставил заявку, его телефон ' .$phone. '<br>Почта этого пользователя: ' .$mail; 
$mail->AltBody = '';

if(!$mail->send()) {
  echo 'Письмо не может быть отправлено. ';
  echo 'Ошибка: ' . $mail->ErrorInfo;
} else {
  header('location: thanks.html');
}                            
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Softer, 2018-11-27
@olyabolya

It's probably worth naming the variables differently though :)

$mail = new PHPMailer();
...
$mail = $_POST["mail"];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question