Como posso instalar e configurar um servidor SMTP?

5

Como posso configurar um servidor SMTP para enviar e-mails como *@meudominio.com.br?

Como posso usar esse servidor SMTP com um script PHP que captura dados postados do formulário de contato do meu site e os envia para mim como um e-mail?

Estou usando o Ubuntu 13.10 e o webmin, mas posso fazer as alterações localmente no servidor.

aqui está o meu script PHP ..

#!/var/www/php
<?php

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





$email_to = "[email protected]";

$email_subject = "havok security contact form";





function died($error) {

    // your error code can go here

    echo "We are very sorry, but there was an error found with the form you submitted. ";

    echo "These errors appear below.<br /><br />";

    echo $error."<br /><br />";

    echo "Please go back and fix these errors.<br /><br />";

    die();

}



// validation expected data exists

if(!isset($_POST['name']) ||

    !isset($_POST['email']) ||

    !isset($_POST['phone']) ||

    !isset($_POST['message'])) {

    died('We are sorry, but there appears to be a problem with the form you submitted.');       

}



$first_name = $_POST['name']; // required

$email_from = $_POST['email']; // required

$telephone = $_POST['phone']; // not required

$comments = $_POST['message']; // required



$error_message = "";

$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

 if(!preg_match($email_exp,$email_from)) {

$error_message .= 'The Email Address you entered does not appear to be valid.<br />';

}

$string_exp = "/^[A-Za-z .'-]+$/";

if(!preg_match($string_exp,$name)) {

$error_message .= 'The Name you entered does not appear to be valid.<br />';

}


if(strlen($message) < 2) {

$error_message .= 'The Message you entered do not appear to be valid.<br />';

}

if(strlen($error_message) > 0) {

died($error_message);

}

$email_message = "Form details below.\n\n";



function clean_string($string) {

  $bad = array("content-type","bcc:","to:","cc:","href");

  return str_replace($bad,"",$string);

}



$email_message .= "Name: ".clean_string($name)."\n";

$email_message .= "Email: ".clean_string($email_from)."\n";

$email_message .= "Phone: ".clean_string($phone)."\n";

$email_message .= "Message: ".clean_string($message)."\n";





   // create email headers

   $headers = 'From: '.$email_from."\r\n".

  'Reply-To: '.$email_from."\r\n" .

  'X-Mailer: PHP/' . phpversion();

  @mail($email_to, $email_subject, $email_message, $headers);  

  ?>



    <!-- include your own success html here -->
    <link rel="stylesheet" type="text/css" media="screen" href="css/reset.css">
    <link rel="stylesheet" type="text/css" media="screen" href="css/style.css">
    <script src="js/jquery-1.7.min.js"></script>
    <script src="js/jquery.easing.1.3.js"></script>
    <script src="js/FF-cash.js"></script>
    <p>&nbsp;</p>
    <p><img src="images/security_logo.png" width="596" height="190" alt="security_logo" longdesc="http://havoksecurity.com" /><img src="images/twitter_icon-1.png" width="24" height="24" alt="twitter_icon" /><img src="images/facebook_icon-2.png" width="24" height="24" alt="facebook_icon" /><img src="images/google_icon-3.png" width="24" height="24" alt="google_icon" /></p>
    <p>&nbsp;</p>
    <p>Thank you for contacting us. We will respond within 24 hours. 
    <?php

    }

    ?>
    </p>

Eu instalei o iRedMail, em uma nova instalação do Ubuntu 12.4, mas ele não enviará nem receberá e-mails. Então parece que vou ter que descobrir isso antes que eu possa fazer isso usar esse script php. toda ajuda seria muito apreciada.

Eu apenas tentei enviar uma mensagem para que eu possa ver o erro aqui é o log de erro

Feb  5 00:53:27 havoksecurity postfix/smtpd[8193]: connect from unknown[192.168.1.126]
Feb  5 00:53:53 havoksecurity postfix/smtpd[8193]: lost connection after UNKNOWN from unknown[192.168.1.126]
Feb  5 00:53:53 havoksecurity postfix/smtpd[8193]: disconnect from unknown[192.168.1.126]
Feb  5 00:57:13 havoksecurity postfix/anvil[8195]: statistics: max connection rate 1/60s for (smtp:192.168.1.126) at Feb  5 00:53:27
Feb  5 00:57:13 havoksecurity postfix/anvil[8195]: statistics: max connection count 1 for (smtp:192.168.1.126) at Feb  5 00:53:27
Feb  5 00:57:13 havoksecurity postfix/anvil[8195]: statistics: max cache size 1 at  Feb  5 00:53:27
Feb  5 01:10:45 havoksecurity postfix/pickup[7985]: DDEACD40FD2: uid=0 from=<[email protected]>
Feb  5 01:10:45 havoksecurity postfix/cleanup[9202]: DDEACD40FD2: message-id=<[email protected]>
Feb  5 01:10:45 havoksecurity postfix/qmgr[1687]: DDEACD40FD2: from=<[email protected]>, size=641, nrcpt=1 (queue active)
Feb  5 01:10:46 havoksecurity amavis[1412]: (01412-06) NOTICE: reconnecting in response to: err=2006, HY000, DBD::mysql::st execute failed: MySQL server has gone away at (eval 100) line 166, <GEN37> line 1834.
Feb  5 01:10:47 havoksecurity postfix/smtpd[9211]: connect from localhost[127.0.0.1]
Feb  5 01:10:47 havoksecurity postfix/trivial-rewrite[9204]: warning: do not list domain havoksecurity.com in BOTH mydestination and virtual_mailbox_domains
Feb  5 01:10:47 havoksecurity postfix/smtpd[9211]: 527E6D40F94: client=localhost[127.0.0.1]
Feb  5 01:10:47 havoksecurity postfix/cleanup[9202]: 527E6D40F94: message-id=<[email protected]>
Feb  5 01:10:47 havoksecurity postfix/qmgr[1687]: 527E6D40F94: from=<[email protected]>, size=1098, nrcpt=1 (queue active)
Feb  5 01:10:47 havoksecurity postfix/smtpd[9211]: disconnect from localhost[127.0.0.1]
Feb  5 01:10:47 havoksecurity amavis[1412]: (01412-06) Passed CLEAN, MYUSERS <[email protected]> -> <[email protected]>, Message-ID: <[email protected]>, mail_id: tx8Bn4bMXniG, Hits: -10, size: 641, queued_as: 527E6D40F94, 1404 ms
Feb  5 01:10:47 havoksecurity postfix/smtp[9207]: DDEACD40FD2: to=<[email protected]>, relay=127.0.0.1[127.0.0.1]:10024, delay=1.6, delays=0.09/0.01/0/1.5, dsn=2.0.0, status=sent (250 2.0.0 from MTA([127.0.0.1]:10025): 250 2.0.0 Ok: queued as 527E6D40F94)
Feb  5 01:10:47 havoksecurity postfix/qmgr[1687]: DDEACD40FD2: removed
Feb  5 01:11:17 havoksecurity postfix/smtp[9219]: connect to gmail-smtp-in.l.google.com[74.125.196.27]:25: Connection timed out
Feb  5 01:11:47 havoksecurity postfix/smtp[9219]: connect to alt1.gmail-smtp-in.l.google.com[173.194.75.27]:25: Connection timed out
Feb  5 01:12:17 havoksecurity postfix/smtp[9219]: connect to alt2.gmail-smtp-in.l.google.com[173.194.78.27]:25: Connection timed out
Feb  5 01:12:47 havoksecurity postfix/smtp[9219]: connect to alt3.gmail-smtp-in.l.google.com[74.125.136.27]:25: Connection timed out
Feb  5 01:13:17 havoksecurity postfix/smtp[9219]: connect to alt4.gmail-smtp-in.l.google.com[173.194.70.27]:25: Connection timed out
Feb  5 01:13:17 havoksecurity postfix/smtp[9219]: 527E6D40F94: to=<[email protected]>, relay=none, delay=150, delays=0.04/0.02/150/0, dsn=4.4.1, status=deferred (connect to alt4.gmail-smtp-in.l.google.com[173.194.70.27]:25: Connection timed out)
    
por HaVoK 25.01.2014 / 00:29

1 resposta

4

Eu recomendaria que você analise algo como o Postfix como seu servidor de e-mail. Isso permitirá que você envie um email.

Apenas certifique-se de que, se quiser executar um servidor de e-mail completo (com tráfego de entrada), configure seu arquivo de zona DNS para manipular o tráfego de e-mail de entrada.

Para o script PHP ao qual você está se referindo ... você quer enviar um e-mail de algo como um formulário, com dados de formulário como parte do e-mail e talvez outras informações padrão?

    
por jokerfive 25.01.2014 / 03:19