Include smtp authentication

0

My site is not sending mail when I put it on the client server, but on my server it sends it correctly (I use HOO.ST), on the client server, it shows this message Servidor de e-mails de saída: grupomenegalli.com.br (o servidor requer autenticação) and also displays this Protocolos de e-mail de saída suportados: SMTP . I think I'll have to use SMTP authentication

Is there any way to just include an authentication in my php?

PHP:

<?php
// Check for empty fields
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message']) || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)){
echo json_encode(array('error'=>'true'));
return false;
}

$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];

$lastname = $_POST['lastname'];
$phone = $_POST['phone'];
$subject = ($_POST['subject'] ? $_POST['subject'] : "Website Contact   Form:  $name");



// Create the email and send the message
$to = '[email protected]';// Add your email address inbetween the ''  replacing [email protected] - This is where the form will send a message to.
$email_subject = $subject;
$email_body = "You have received a new message from your website   contact form.\n\n"."Here are the details:\n\nName: $name\n\nLast Name:     $lastname\n\nEmail: $email_address\n\nPhone:  $phone\n\nMessage:\n$message";
$headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected].
$headers .= "Reply-To: $email_address"; 
mail($to,$email_subject,$email_body,$headers);
echo json_encode(array('success'=>'true'));
return true;            
?>
    
asked by anonymous 19.09.2016 / 21:05

1 answer

0

I do not quite understand your doubt, but it seems to me that you normally send via localhost (local server) but when you try to send with an external server (your client) SMTP authentication error, password, port, and script host for your client, if you want to send via external SMTP you will need to set these values in your script, see this example with a smtp from criarsiteweb.net:

<?php
 $from = "Seu nome <[email protected]>";
 $to = "Destinatario <destinatario@site,com>";
 $subject = "Assunto";
 $body = "Conteúdo";

 $host = "criarsiteweb.net";
 $port = "587";
 $username = "usuário_smtp";
 $password = "senha_smtp";

 $headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject);
 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'port' => $port,
     'auth' => true,
     'username' => $username,
     'password' => $password));

 $mail = $smtp->send($to, $headers, $body);

 if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  } else {
   echo("<p>Mensagem enviada!</p>");
  }
 ?>

If you do not want to use username and password you will need to configure the server's ip as authorized in the sending SMTP, DO NOT ACTIVATE ANIMAL AUTHENTICATION, just authorize your host's ip if you want to dispense with the username and password, if you prefer to use a phpmail function with sendmail directly on the localhost

    
20.06.2017 / 08:20