如何安装和配置 SMTP 服务器?

如何安装和配置 SMTP 服务器?

我该如何设置 SMTP 服务器以 *@mydomain.com 的身份发送电子邮件?

那么,我如何使用这个 SMTP 服务器和 PHP 脚本来抓取从我的网站联系表单发布的数据并将其作为电子邮件发送给我?

我正在使用 Ubuntu 13.10 和 webmin,但我可以在服务器上本地进行更改。

这是我的 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>

我在全新安装的 Ubuntu 12.4 上安装了 iRedMail,但它无法发送或接收电子邮件。因此,看来我必须先弄清楚这一点,然后才能让它使用此 php 脚本。非常感谢大家的帮助。

我刚刚尝试发送一条消息,这样我就可以看到错误,这是错误日志

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)

答案1

我建议你看看类似 Postfix 的东西作为您的电子邮件服务器。这将允许您发送电子邮件。

只要确保,如果您想运行完整的电子邮件服务器(具有入站流量),您就设置 DNS 区域文件来处理入站邮件流量。

对于您所指的 PHP 脚本...您的意思是您想从类似表单的东西发送电子邮件,并将表单数据作为电子邮件的一部分,也许还包含一些其他默认信息?

相关内容