Include smtp authentication

Asked

Viewed 66 times

0

My site is not sending emails when I put it on the client’s server, but on my site it sends it correctly (I use HOO.ST), on the client’s server, it shows this message Servidor de e-mails de saída: grupomenegalli.com.br (o servidor requer autenticação) and also presents this Protocolos de e-mail de saída suportados: SMTP. I think I’ll have to use an 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;            
?>

1 answer

0

I don’t quite understand your question, but it seems to me that you usually send via localhost (local server) but when you try to send with an external server (from your client) returns SMTP authentication error, if that is, check the user, password, port, and host script 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 an smtp from creatsiteweb.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 user and password you will need to configure the server ip as authorized in the SMTP of submissions, NOT ACTIVATE THE ANÔMICA AUTHENTICATION, only authorize the ip of your host if you want to waive the user and password, make sure to adapt your code for SMTP connection or if you prefer you can use a phpmail function with sendmail directly on the local server (localhost)

Browser other questions tagged

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