-1

用户填写反馈表并向我们发送邮件。我想使用 phpmail()函数。请帮助如何使用php脚本?我需要什么东西?

我是新手,你能帮帮我吗?

我的表单代码:

<form name="contact" method="post" action="sendmail.php" enctype="multipart/form-data" onsubmit="return checkForm(this);">
<table style="width:100%;height:40px;"><tr><td align="right"><span id="error" style="color:#FF0000;">&nbsp;</span></td></tr></table>
<label><span>First Name:</span><input type="text" name="fname" id="fname"/></label>
<label><span>Last Name:</span><input type="text" name="lname"/></label>
<label><span>Email Address:</span><input type="text" name="email"/></label>
<label><span>Phone No. :</span><input type="text" name="phone"/></label>
<label class="last"><span>Feedback :</span><textarea name="message" cols="" rows=""></textarea></label>
<label class="btnsub"><input name="" type="submit" title="submit" class="submission"/></label>
</form>
4

1 回答 1

2

发送邮件.php

<?php
if (isset($_POST['sendmail'])) {
    //catch and validate user inputs
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $phone = $_POST['phone'];

    //send mail using php's mail function
    $to      = 'tomail@gmail.com';
    $subject = 'FeedBack';
    //appended extra information just to show that you can do it like this way
    $message = $fname. " " . $lname .", " . $_POST['message'] . $phone;
    $headers = 'From:' . $_POST['email']. "\r\n" .
        'Reply-To:' . $_POST['email'] ."\r\n" .
        'X-Mailer: PHP/' . phpversion();

    // Please specify your Mail Server - Example: mail.yourdomain.com.
    //If you are testing on localhost, then make sure that mailserver is running on localhost
    ini_set("SMTP","localhost");

    // Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
    ini_set("smtp_port","25");

    mail($to, $subject, $message, $headers);
    //refer this URL:http://php.net/manual/en/function.mail.php
}
?>

注意:您不应该直接在脚本中使用用户输入。绝不。我刚刚向您展示了如何使用邮件功能而不是整个过程的示例。请在脚本中使用之前验证用户输入。您可以从我上面提到的 URL 中获得更好的想法。

如果您要从用户那里获取一些信息,例如名字和姓氏和电话号码,那么最好以某种方式通过电子邮件将其传递给您。所以,我已经更新了答案,让您对此有所了解。

于 2013-01-05T06:50:00.860 回答