-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 send_email.php file:
<?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 completed and the fields are submitted via post to the action send_email.php
, nothing happens in this URL.
in 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 empty). As I am developing this app in sublime text, I ended up not being able to debug the logical part well. (I tried to implement the package Xdebug in sublime but I had difficulties in use).
I’ve already deleted all that code from send_email.php
, leaving only the phpinfo()
to test whether the php
is working (and is!).
Funny thing is, even if I $email = $_POST['email'];
shortly after the <?php
and then print a echo $email
, yet nothing appears
I just found out there’s something wrong with require.
– Mikhael Araujo
Try it like this
require_once 'PHPMailer/PHPMailerAutoload.php';
... Probably the folder path is incorrect. If you have the folderPHPMailer
in the same directory assend_email.php
then that’s how it is. If not, post how your structure is.– rbz
require_once 'vendor/Composer/autoload_real.php'; require_once 'vendor/autoload.php'; require_once 'vendor/phpmailer/phpmailer/src/Phpmailer.php'; in the same folder as the send_email.php file, there is a vendor folder with this directory..
– Mikhael Araujo
I still can’t instantiate a Phpmailer class object.
– Mikhael Araujo
You need to get to
PHPMailerAutoload.php
... So you have to go into the folders... ex.:require_once 'vendor/PHPMailer/PHPMailerAutoload.php';
.. the default Phpmailer folder, already has thePHPMailerAutoload.php
at the root. If yours is different, look for theautoload.php
, and make your way to him.– rbz
I added it in the current version (6.0.3). https://github.com/PHPMailer/PHPMailer
– rbz