【问题标题】:HTML form submit automated email using PHPHTML 表单使用 PHP 提交自动电子邮件
【发布时间】:2014-11-01 13:41:37
【问题描述】:

我创建了一个 HTML 表单,没有任何困难(我对 HTML 和 CSS 比较陌生,但对它们很熟悉)。问题是我希望提交按钮将用户在表单中输入的数据发送到我的电子邮件地址。

我的 PHP 知识几乎不存在,我完全陷入困境。如果有人有耐心提供帮助,将不胜感激。

这是表单的代码...

    <!DOCTYPE html>

<html>

  <head>
    <meta charset="utf-8">
    <title>Life Academy | Pre-course questionnaire</title>
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="pcq.css">
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700,800' rel='stylesheet' type='text/css'>    
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
  </head>

  <body>
    <div id="formbg">
    <div id="formcontent">
        <img src="pcqlogo.png" class="logo">
        <p><strong>Retirement Planning Course<br>Anonymous Pre-course Questionnaire</strong><br>So that the course may more accurately reflect your interests and possible concerns, we would like you to complete and return this questionnaire before the start of the course, by email, to<br> <a href="mailto:info@life-academy.co.uk"><strong>info@life-academy.co.uk</strong>.</a></p>
        <form>
            Age<br> <input type="text" name="age"><br>
            Years with present/last company<br> <input type="text" name="yearswithcompany"><br>
            Leaving Date<br> <input type="text" name="leavingdate"><br>
            Job Role<br> <input type="text" name="role"><br>

            Do you have a company or occupational pension plan?<br>
            <input id="yes" type="radio" name="companypension" value="yes">
            <label for="yes">Yes</label>
            <input id="no" type="radio" name="companypension" value="no">
            <label for="no">No</label><br>

            Do you have a personal &#40private&#41 pension plan?<br>
            <input id="yes" type="radio" name="personalpension" value="yes">
            <label for="yes">Yes</label>
            <input id="no" type="radio" name="personalpension" value="no">
            <label for="no">No</label><br>

            What would you like to gain from this course? Please describe in detail.<br> <textarea name="liketogain" class="largetextbox"></textarea><br>
            What are your main activities outside of work?<br> <input type="text" name="activities"><br>
            How do you think these activities will develop/change in the near future?<br> <textarea name="activitiesdevelop" class="largetextbox"></textarea><br>
            Have you any concerns about the future? If so, list them here:<br> <textarea name="futureconcerns" class="largetextbox"></textarea><br>
            Do you want to make changes to your health/lifestyle? If so, please describe the changes.<br> <textarea name="healthlifestylechanges" class="largetextbox"></textarea><br>
            How would you like the emphasis of your life to change in the future with respect to work/voluntary activity?<br> <textarea name="work" class="largetextbox"></textarea><br>
            Do you have any dietary requirements?<br> <input type="text" name="diet"><br>
            Do you have any other special requirements?<br> <textarea name="special" class="largetextbox"></textarea><br>
            <input type="submit" value"submit">
        </form>
    </div>
    </div>
  </body>

</html>

【问题讨论】:

  • ...换句话说,您正在寻找一个 PHP 处理程序来发送邮件,对吗?

标签: php html forms email


【解决方案1】:

为自己创建一个 PHP 提交页面并将你的表单设置为 POST:

<form action="file_name.php" method="POST">
//form fields go here
</form>

然后你需要一个 PHP 邮件类。我推荐 PHPMailer。
基本使用及下载:https://github.com/PHPMailer/PHPMailer

这样的文件:
PHP_mailer.php

<?php 
include 'mailer';
include 'library';
include 'files';
....rest of mailer code goes here....
?>

在 PHP 邮件页面上,您可以使用 $_POST['name of field goes here'] 访问任何设置的字段。所以前。 $_POST['name']$_POST['age']

请注意,这是一个非常基本的解释,需要额外的步骤,例如表单验证,很可能使用 Javascript,并且需要您对电子邮件的格式进行一些设置,等等。最好的选择是尝试和测试自己动手,直到你可以让它工作。如果有些东西难以掌握,还有大量的 PHP 文档可供使用。

【讨论】:

    猜你喜欢
    • 2018-11-05
    • 1970-01-01
    • 2016-04-25
    • 2012-01-12
    • 1970-01-01
    • 2013-09-16
    • 2015-11-11
    • 2015-02-06
    • 2015-11-18
    相关资源
    最近更新 更多