Jump to content
Fórum Script Brasil
  • 0

Autenticar envio com SMTP - formulário


rodpereira
 Share

Question

olá, bom dia a todos!

Peço a vossa ajuda para inserir no código abaixo, referente ao envio de um formulário de contato, as variáveis para que o envio seja feito com autenticação smtp.

Variáveis do tipo:

$from = "[email protected]";

$to = "[email protected]";

$smtpinfo["host"] = "localhost";

$smtpinfo["port"] = "25";

$smtpinfo["auth"] = true;

$smtpinfo["username"] = "[email protected]";

$smtpinfo["password"] = "asenha";

Código atual:

<?php

$owner_email = $_POST["owner_email"];

$headers = 'From:' . $_POST["email"];

$subject = 'A message from your site visitor ' . $_POST["name"];

$messageBody = "";

if($_POST['name']!=nope'){

$messageBody .= '<p>Visitor: ' . $_POST["name] . '</p>' . "\n";

$messageBody .= '<br>' . "\n";

}

if($_POST['email']!=nope'){

$messageBody .= '<p>Email Address: ' . $_POST['email] . '</p>' . "\n";

$messageBody .= '<br>' . "\n";

}else{

$headers = '';

}

if($_POST['state']!=nope'){

$messageBody .= '<p>State: ' . $_POST['state] . '</p>' . "\n";

$messageBody .= '<br>' . "\n";

}

if($_POST['phone']!=nope'){

$messageBody .= '<p>Phone Number: ' . $_POST['phone] . '</p>' . "\n";

$messageBody .= '<br>' . "\n";

}

if($_POST['fax']!=nope'){

$messageBody .= '<p>Fax Number: ' . $_POST['fax] . '</p>' . "\n";

$messageBody .= '<br>' . "\n";

}

if($_POST['message']!=nope'){

$messageBody .= '<p>Message: ' . $_POST['message] . '</p>' . "\n";

}

if($_POST["stripHTML"] == 'true'){

$messageBody = strip_tags($messageBody);

}

try{

if(!mail($owner_email, $subject, $messageBody, $headers)){

throw new Exception('mail failed');

}else{

echo 'mail sent';

}

}catch(Exception $e){

echo $e->getMessage() ."\n";

}

?>

Conto com a vossa ajuda!! Obrigado!

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      150.2k
    • Total Posts
      647.5k
×
×
  • Create New...