简体   繁体   中英

How can I get FORMS to send to my EMAIL (php)?

I have been working on this form. Have watched all kinds of video tutorials and bloqs, still can't get my form to be e-mailed to me when filled out and submitted.

Can somebody please provide a solution for this?

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>

In order to append a string in PHP you need the . operator.

So,

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

And,

$headers = 'From: ' . $email;

Try that out and let us know if you still have problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM