如何让FORMS发送到我的EMAIL(php)?

时间:2013-11-08 20:15:24

标签: php forms email

我一直在研究这个表格。看过各种视频教程和bloqs,在填写和提交时仍然无法通过电子邮件发送给我。

有人可以为此提供解决方案吗?

INDEX.HTML

<html>
<head>
 <title>Application</title>

</head>

 <body>

<form action="submit.php" method="POST">

<h3>Please fill out the following form:</h3>

<div id="form">
<table cellpadding="10">
<tr>
<td>Full Name:<br><input type="text" name="fullname">
<td>Title:<br><input type="text" name="title">
</tr>   
<tr>
<td>Company Name:<br><input type="text" name="company">
<td>Website:<br><input type="text" name="website">
</tr>
<tr>
    <td>Email Address:<br><input type="text" name="email">
    <td>Telephone:<br><input type="text" name="telephone">
</tr>
<tr>
    <td>Street Address:<br><input type="text" name="address">
    <td>City:<br><input type="text" name="city">
</tr>
<tr>
    <td>State:<br><input type="text" name="state">
    <td>Zip Code:<br><input type="text" name="zipcode">
</tr>
</table>
</div>

<input type="submit" value="Submit">

</form>
</body>
</html>

SUBMIT.PHP

<html>
<head>
<title>Application Submitted</title>

<?php

if (isset($_POST['fullname']) && isset($_POST['title']) && isset($_POST['company'])      && isset($_POST['website']) && isset($_POST['email']) && isset($_POST['address']) && isset($_POST['city']) && isset($_POST['state']) && isset($_POST['zipcode']) && isset($_POST['telephone'])) {

    $fullname = $_POST['fullname'];
    $title = $_POST['title'];
    $company = $_POST['company'];
    $website = $_POST['website'];
    $email = $_POST['email'];
    $address = $_POST['address'];
    $city = $_POST['city'];
    $state = $_POST['state'];
    $zipcode = $_POST['zipcode'];
    $telephone = $_POST['telephone'];

if (!empty($fullname) && !empty($title) && !empty($company) && !empty($website) && !empty($email) && !empty($address) && !empty($city) && !empty($state) && !empty($zipcode) && !empty($telephone)) {
    $to = 'myemail@mail.com';
    $subject = 'Application Submitted...';
    $body = $fullname "\n" $title "\n" $company "\n" $website "\n" $email "\n" $address "\n" $city "\n" $state "\n" $zipcode "\n" $telephone;
    $headers = 'From: '$email;
if (mail($to, $subject, $body, $headers))
    echo 'Thank you for your interest!';
} else {
    echo 'All fields are required!';
}
}

?>

</head>
<body>
</body>
</html>

1 个答案:

答案 0 :(得分:2)

要在PHP中附加字符串,您需要.运算符。

所以,

$body = $fullname . "\n" . $title . "\n" . $company . "\n" . $website . "\n" . $email . "\n" . $address . "\n" . $city . "\n" . $state . "\n" . $zipcode . "\n" . $telephone;

$headers = 'From: ' . $email;

尝试一下,如果您还有问题请告诉我们。