I
I
Ilya Filonov2020-06-16 08:54:59
PHP
Ilya Filonov, 2020-06-16 08:54:59

How to connect PHPMailer to opencart?

Good afternoon. The site has a feedback form.

<div class="sale">
                    <h1>Вы у нас первый раз? Вам скидка 20%!</h1>
                    <b><form action="catalog/view/theme/marvi/html/php/mail.php" method="POST"></b>
                        <div class="row">                        
                            <div class="user-info col-12 col-lg-8">
                                <div class="row">
                                    <div class="col-lg-6">
                                    <input type="text" name="user_name" id="" placeholder="Ваше имя">
                                </div>
                                <div class="col-lg-6">
                                    <input type="text" name="user_phone" id="phone" placeholder="+7 (___) ___-__-__">                            
                                </div>
                                </div>
                            </div>
                            <div class="col-12 col-lg-4">
                                <input type="submit" value="ПОЛУЧИТЬ СКИДКУ">
                            </div>
                        </div>
                    </form>
                    <p class="privacy">Нажимая на кнопку...</a></p>
                </div>

This form refers to the mail.php file.
<?php 

require_once('catalog/view/theme/marvi/html/phpmailer/PHPMailerAutoload.php');
$mail = new PHPMailer;
$mail->CharSet = 'utf-8';

$name = $_POST['user_name'];
$phone = $_POST['user_phone'];

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

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

$mail->setFrom('******'); // от кого будет уходить письмо?
$mail->addAddress('******');     // Кому будет уходить письмо 

$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Заявка на скидку с сайта';
$mail->Body    = '' .$name . ' оставил(а) заявку, телефон - ' .$phone;
$mail->AltBody = '';

// if(!$mail->send()) {
//     echo 'Error';
// } else {
//     header('location: thank-you.html');
// }
// ?>

However, when you click on the "Get a discount" button, it takes you to a page like sitename/mail.php and, of course, does not find such a page.
5ee85e1b834e6631613978.png

I suspect that the problem is in the paths to mail.php and PHPMailer itself, but if so, I can't figure out how to write them correctly. If not, then I don't know what the problem is.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
web-mechanic, 2020-06-24
@amfetamine

you connect the class like all other classes, and implement the functionality through the controller.
The problem itself is in the routing most likely

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question