Answer the question
In order to leave comments, you need to log in
Why are emails not being sent using PHPMailer?
My code:
<?php
$phone = $_POST['user'];
require_once('phpmailer/PHPMailerAutoload.php');
$mail = new PHPMailer;
$mail->CharSet = 'utf-8';
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // Наш логин
$mail->Password = 'xxxxxxx'; // Наш пароль от ящика
$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]'); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Новая заявка сайта';
$mail->Body = '
Пользователь оставил свои данные <br>
Имя: неизвестно <br>
Телефон: ' . $phone . '';
$mail->AltBody = 'Это альтернативный текст';
if(!$mail->send()) {
echo 'Письмо не может быть отправлено. ';
echo 'Ошибка: ' . $mail->ErrorInfo;
} else {
header('location: ../thankyou.html');
}
?>
<form action="mailer/smart.php" method="POST" class="main-form_post">
<input type="tel" class="popup-form__input" id="phone" name="user" required placeholder="+7 (ХХХ) ХХХ-ХХ-ХХ">
Answer the question
In order to leave comments, you need to log in
>SMTP connect() failed
1. Is all data correct? Maybe port 587?
2. Are all php libraries for working with smtp installed?
3. Is there a firewall on the server (iptables\ufw)? If this is an Amazon server, is it allowed to connect to the smtp port in the security groups?
Sign-in attempt blocked: untrusted application
Someone wanted to sign into your account through an untrusted application. We blocked this attempt.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question