Answer the question
In order to leave comments, you need to log in
Trouble sending PHPMailer emails?
To order a callback I use the phpmailer library. On the local machine, everything works fine and is sent, and after the transfer, the real server has this error
Письмо не отправлено<br />
<b>Catchable fatal error</b>: Object of class PHPMailer could not be converted to string in <b>/home
/u112570048/public_html/mail.php</b> on line <b>39</b><br />
<?php
if($_POST) {
//Переменные
$name = $_POST['name'];
$phone = $_POST['phone'];
$site = 'RobotsShow.ru';
require 'phpmailer/class.phpmailer.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.yandex.ru';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]*********.ru'; // логин от вашей почты
$mail->Password = '*********'; // пароль от почтового ящика
$mail->SMTPSecure = 'ssl';
$mail->Port = '465';
$mail->From = '[email protected]**********.ru';
$mail->FromName = 'Перезвони';
$mail->AddAddress('[email protected]**********.ru');
$mail->isHTML(true);
$mail->Subject = $name . ' просит перезвонить!';
$mail->Body = "Поступил заказ обратного звонка с сайта {$site} : <br/> <b>Имя:</b> {$name}<br/><b>Телефон:</b> {$phone}<br/><b>E-mail:</b> {$_POST['email']}";
$mail->AltBody = "Поступил заказ обратного звонка с сайта: \r\n Имя: {$name}\r\nТелефон: {$_POST['phone']}\r\nE-mail: {$_POST['email']}";
if( $mail->send() ) {
echo 'Письмо отправлено!';
}else{
echo 'Письмо не отправлено ';
echo 'Ошибка: ' . $mail->errorInfo;
}
}
Answer the question
In order to leave comments, you need to log in
If Host is from smtp.yandex.ru, then Username is Yandex mail (Password is its password), where From is the same Yandex mail as in Username, otherwise it will not be sent.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question