2010-02-16 137 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()函數沒有正確的數據轉義可能是攻擊和自定義頁眉注射非常脆弱。