error sending email in php using phpmailer

Asked

Viewed 131 times

-1

Follow my php and html code

<?php


require("PHPMailer/PHPMailerAutoload.php");

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


$enviaFormularioParaNome = 'Lucas';
$enviaFormularioParaEmail = '[email protected]';

$caixaPostalServidorNome = 'user';
$caixaPostalServidorEmail = '[email protected]';
$caixaPostalServidorSenha = 'senha';


$remetenteNome  = $_POST['nome'];
$remetenteEmail = $_POST['email'];
$assunto  = $_POST['tipoQuarto'];
$mensagem = $_POST['telefone'];
$entrada = $_POST['data1'];
$saida = $_POST['data2'];

$mensagemConcatenada = 'Solicitação de Reserva'.'<br/>'; 
$mensagemConcatenada .= '-------------------------------<br/><br/>'; 
$mensagemConcatenada .= 'Nome: '.$remetenteNome.'<br/>'; 
$mensagemConcatenada .= 'E-mail: '.$remetenteEmail.'<br/>'; 
$mensagemConcatenada .= 'Quarto: '.$assunto.'<br/>';
$mensagemConcatenada .= 'Entrada: '.$entrada.'<br/>';
$mensagemConcatenada .= 'Saída: '.$saida.'<br/>';
$mensagemConcatenada .= '<br/>'; 
$mensagemConcatenada .= 'Telefone: "'.$mensagem.'"<br/>';




require_once('PHPMailer/PHPMailerAutoload.php');

$mail = new PHPMailer();

$mail->IsSMTP();
$mail->SMTPAuth  = true;
$mail->Charset   = 'utf8_decode()';
$mail->Host  = 'smtp.'.substr(strstr($caixaPostalServidorEmail, '@'), 1);
$mail->Port  = '587';
$mail->Username  = $caixaPostalServidorEmail;
$mail->Password  = $caixaPostalServidorSenha;
$mail->From  = $caixaPostalServidorEmail;
$mail->FromName  = utf8_decode($caixaPostalServidorNome);
$mail->IsHTML(true);
$mail->Subject  = utf8_decode($assunto);
$mail->Body  = utf8_decode($mensagemConcatenada);


$mail->AddAddress($enviaFormularioParaEmail,utf8_decode($enviaFormularioParaNome));

if(!$mail->Send()){
$mensagemRetorno = 'Erro ao enviar formulário: '. print($mail->ErrorInfo);
}else{
$mensagemRetorno = 'Formulário enviado com sucesso!';
} 


}?>

<!DOCTYPE html>

                <div class="col-lg-6 col-md-6 tm-contact-form-input col-lg-offset-3">
                    <div class="form-group">
                        <select name="tipoQuarto" id="finputtipo" class="form-control">
                            <option value="Quarto Individual">Quarto Individual</option>
                            <option value="Quarto Duplo">Quarto Duplo</option>
                            <option value="Quarto Triplo">Quarto Triplo</option>
                            <option value="Apartamento Individual">Apartamento Individual</option>
                            <option value="Apartamento Duplo">Apartamento Duplo</option>
                            <option value="Apartamento Triplo">Apartamento Triplo</option>
                            <option value="Apartamento individual com Ar">Apartamento individual com Ar</option>
                            <option value="Apartamento duplo com Ar">Apartamento duplo com Ar</option>
                            <option value="Apartamento de casal">Apartamento de casal</option>
                            <option value="Apartamento de casal com Ar">Apartamento de casal com Ar</option>
                            <option value="Apartamento de casal família com Ar">Apartamento de casal família com Ar</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <input type="text" name="nome" id="nome" class="form-control" placeholder="Nome" />
                    </div>
                    <div class="form-group">
                        <input type="email" name="email" id="email" class="form-control" placeholder="Email" />
                    </div>
                    <div class="form-group">
                        <input type="text" name="fone" id="telefone" class="form-control" placeholder="Telefone" />
                    </div>
                    <div class="form-group">
                                        <div class='input-group date'  id='datetimepicker1'>
                                            <input type='text' class="form-control" name="data1" placeholder="Data de Entrada" />
                                            <span class="input-group-addon">
                                                <span class="fa fa-calendar"></span>
                                            </span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class='input-group date' id='datetimepicker2'>
                                            <input type='text' class="form-control" name="data2" placeholder="Data de Saída" />
                                            <span class="input-group-addon">
                                                <span class="fa fa-calendar"></span>
                                            </span>
                                        </div>
                                    </div>
                    <div class="form-group">
                        <textarea id="obs" name="obs" class="form-control" rows="6" placeholder="Observação"></textarea>
                    </div>
                    <div class="form-group">
                        <button class="tm-submit-btn" type="submit" name="submit">Reservar</button> 
                    </div>               
                </div>
            </form>
        </div>          
    </div>
</section>

  • You are requiring the file PHPMailerAutoload.php, but is making a mistake in PHPMailer-master/PHPMailerAutoload.php? Strange.

  • is giving another error.. I edited

  • Better define "new error". Does the first no longer occur? What has changed in your code?

  • If you are in the same directory just Phpmailerautoload.php and not Phpmailer-master/Phpmailerautoload.php

  • The first error no longer occurs because I changed the line PHPMailer-master/PHPMailerAutoload.php for PHPMailerAutoload.php... but now you’ve made that last mistake.

  • 1

    phpmailer requires the classes class.phpmailer.php class.pop3.php class.smtp.php that should be in the same directory

  • I put these three classes and put the require and this error appears: Warning: require(class.phpmailer.php) [function.require]: failed to open stream: No such file or directory

  • So edit your question and clarify your problem better. Put the structure of files and directories you are using, as well as the code.

  • I created a folder called phpmailer and put the three files there

  • your file you saved in the same folder phpmailer? or in a previous directory?

  • in this case the four files must be in the phpmailer folder and in the send page.php must be require "phpmailer/Phpmailerautoload.php";

  • What? It worked? Sleep coming this way

  • so that two require in php? require("Phpmailer/Phpmailerautoload.php"); and require_once('Phpmailer/Phpmailerautoload.php');

  • just one require

  • gave certooooooooo... I took the require the most

  • I’ll set off fires hahaha

Show 11 more comments

1 answer

0


So that the PHPMailer work properly four files are required:

- PHPMailerAutoload.php
- class.phpmailer.php
- class.pop3.php
- class.smtp.php

Download these four files directly from repository library.

It is important that the four files are in the same directory. For convenience, place them inside a unique directory, called PHPMailer. Therefore, your application should look like:

enviar.php
PHPMailer/
    PHPMailerAutoload.php
    class.phpmailer.php
    class.pop3.php
    class.smtp.php

In the archive enviar.php, just put:

require("PHPMailer/PHPMailerAutoload.php");

Other files will be automatically included when required by the library.

Once done, you can use the library normally:

$mail = new PHPMailer;
...
  • in my case just the last 3, you can enter my page and send an email that will arrive here for me

  • Yes, but it’s not good practice (for beginners) from the moment the library’s own documentation recommends using the autoload.

  • i did as you asked.. I put all the files in Phpmailer;.... error: require(PHPMailer/PHPMailerAutoload.php) [function.require]: failed to open stream: No such file or directory in

  • is vdd, there has been change and I have not updated pq yet it works and tinkering with something now can go bad, pq use it on various websites

  • How the file is running enviar.php?

  • The html form is in the same send.php file.

  • send.php is in which directory?

  • in the site root directory...

  • Then edit your question and put ALL the code, please. Put the folder structure as well. No one has crystal ball to figure out what you’re doing.

  • might be just the php part?

  • And the HTML form.

Show 6 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.