2010-02-16 72 views

回答

2

PHP邮件最简单。

<?php 

$message = "This is my e-mail message."; 

mail('[email protected]', 'Message subject', $message); 

?> 

的PEAR包MailMail_Mime有很多有用的功能来发送邮件,也是如此。接受用户的输入,建立一条消息并发送。除此之外,我们需要知道您遇到了什么问题。

1

一个非常简单的联系表单可能看起来像这样。请注意,这仅仅用于演示。我不建议使用此原样:

<?php 

    // If our form has been submitted 
    if ($_POST["submit"]) { 
    // Gather up some values 
    $name = $_POST["username"]; 
    $msg = $_POST["message"]; 
    $errors = false; 
    // If the name and message aren't empty 
    if (!empty($name) && !empty($msg)) { 
     // Email them to ourselves 
     mail("[email protected]", "Website Email", "{$name} says: {$msg}"); 
    } else { // If they are empty 
     // Set an error message 
     $errors = "Please fill out the form."; 
    } 
    // If we have errors as this point, show them 
    if ($errors) print "<p>".$errors."</p>"; 
    } 

?> 
<form method="post"> 
    <p>Name: <input type="text" name="username" /></p> 
    <p>Message: <textarea name="message"></textarea></p> 
    <p><input type="submit" name="submit" /></p> 
</form> 
1

德看看http://swiftmailer.org/,使用mail()函数没有正确的数据转义可能是攻击和自定义页眉注射非常脆弱。