Failed to read a .php file (PHPMailer lib)

-1

Hello! I have the following form:

<form role="form" method="post" action="send_email.php" id="formContato">
            <div class="left">
                <fieldset class="mail"><input placeholder="Endereço e-mail" type="text" name="email" id="email"></fieldset>
                <fieldset class="name"><input placeholder="Primeiro nome" type="text" name="primeiro_nome" id="primeiro_nome"></fieldset>
                <fieldset class="name"><input placeholder="Segundo nome" type="text" name="ultimo_nome" id="ultimo_nome"></fieldset>
                <fieldset class="name"><input placeholder="Telefone" type="text" name="telefone" id="telefone"></fieldset>
                <fieldset class="subject">
                    <select name="assunto" id="assunto">
                  aias,      <option>Dúvida</option>
                        <option>Reclamações</option>
                        <option>Outros</option>
                    </select>
                </fieldset>
            </div>
            <div class="right">
                <fieldset class="question">
                    <textarea  name="mensagem" id="mensagem" placeholder="Digite sua mensagem..."></textarea></fieldset>
            </div>
            <div class="btn-holder">
                <button class="btn blue" type="submit" value="enviar" name="enviar" id="enviar">Enviar</button>
            </div>
</form>

and the file send_email.php:

<?php

require 'PHPMailerAutoload.php';
require 'vendor/autoload.php';
require 'PHPMailer';

if(isset($_POST['enviar'])){

// Fetching data that is entered by the user
    $email = $_POST['email'];
    $primeiro_nome = $_POST['primeiro_nome'];
    $ultimo_nome = $_POST['ultimo_nome'];
    $mensagem = $_POST['mensagem'];
    $assunto = $_POST['assunto'];
    $telefone = $_PPOST['telefone'];
    $to_id = '[email protected]';

// Configuring SMTP server settings
    $mail = new PHPMailer;
    $mail->isSMTP();
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 587;
    $mail->SMTPSecure = 'tls';
    $mail->SMTPAuth = true;
    $mail->Username = $to_id;
    $mail->Password = 'senha';

// Email Sending Details
    $mail->addAddress($to_id);
    $mail->Subject = $assunto;
    $mail->msgHTML($email . "\r\n" .$mensagem);

// Success or Failure
    if (!$mail->send()) {
        $error = "Mailer Error: " . $mail->ErrorInfo;
        echo '<p id="para">'.$error.'</p>';
    }
    else {
        echo '<p id="para">Message sent!</p>';
    }
}
else{
        echo '<p id="para">Please enter valid data</p>';
    }
?>

The problem is that when the form is populated and the fields are submitted via post to the action send_email.php , nothing happens at this URL. in the case, the URL would be: localhost/site/index.html , where the form is filled and then, when submitted, goes to localhost / site / send_email.php (however, this page is blank). As I'm developing this app in the sublime text, I just can not debug the logical part well. (I already tried to implement the xdebug package in sublime but I had difficulties in using it). I already deleted all this code from send_email.php , leaving only phpinfo() to test if php is working (and it is!).

Funny, even if I $email = $_POST['email']; soon after <?php and then start echo $email , still nothing appears

    
asked by anonymous 18.03.2018 / 14:24

1 answer

0

Given your script is correct.

To debug the PHPMailer , add:

$mail->SMTPDebug = 2;

or

$mail->SMTPDebug = SMTP::DEBUG_SERVER;

Options:

  • SMTP :: DEBUG_OFF (0) : Disables debugging (you can also leave it completely, 0 is the default).
  • SMTP :: DEBUG_CLIENT (1) : Output of messages sent by the client.
  • SMTP :: DEBUG_SERVER (2) : as 1, more responses received from server (this is the most useful configuration).
  • SMTP :: DEBUG_CONNECTION (3) : as 2, more information about the initial connection - this level can help diagnose faults in the STARTTLS.
  • SMTP :: DEBUG_LOWLEVEL (4) : as 3, more level information more low, very detailed, do not use for SMTP debugging, only problems.

Documentation

  

I just found out that there is something wrong with require. - Mikhael Araujo

You have to guess where to find PHPMailerAutoload.php in your send_email.php

Examples:

For PHPMailer (5.2-stable) ( Link ):

(rename folder for PHPMailer)

In the same directory:

require_once 'PHPMailer/PHPMailerAutoload.php';

Previous directory:

require_once '../PHPMailer/PHPMailerAutoload.php';

If you are in the latest version (6.0.3):

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';
    
18.03.2018 / 14:49