Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8720709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:05:52+00:00 2026-06-13T07:05:52+00:00

I would like to create a contact form, where the email is sent along

  • 0

I would like to create a contact form, where the email is sent along with an auto-generated attachment file (.txt). The attachment should include all the values of the input fields present in the contact form (whether they are empty or not). Can this be done by using PHP mail()? My code now can only send the contact form contents as the email body:

<?php
define("WEBMASTER_EMAIL", 'info@email.com'); 
error_reporting (E_ALL); 


if(!empty($_POST))
{
$_POST = array_map('trim', $_POST); 
$name = htmlspecialchars($_POST['name']);
$email = $_POST['email'];
$subject = htmlspecialchars($_POST['subject']);
$message = htmlspecialchars($_POST['message']);

$error = array();


if(empty($name))
{

$error[] = 'Please enter your name';

}


if(empty($email))
{

$error[] = 'Please enter your e-mail';


}

 elseif(!filter_var($email, FILTER_VALIDATE_EMAIL))
{ 

$error[] = 'e-mail is incorrect';

}


if(empty($message) || empty($message{15})) 
{

$error[] = "Please enter message more than 15 characters";

}

if(empty($error))
{  

$body = '
<html>
<head>
<title></title>
</head>
<body>
<table>
<tr><td>Name: </td><td>&nbsp;</td><td>'.$name.'</td><tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>Email: </td><td>&nbsp;</td><td>'.$email.'</td><tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>Subject: </td><td>&nbsp;</td><td>'.$subject.'</td><tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>Message: </td><td>&nbsp;</td><td>'.stripslashes($message).'</td><tr>
</table>
</body>
</html>
';


$mail = mail(WEBMASTER_EMAIL, 'Message sent from website', $body,
    "MIME-Version: 1.0" . "\r\n"
."Content-type: text/html; charset=UTF-8" . "\r\n"
."From: ".$email." \r\n"
    ."Reply-To: ".$email."\r\n"
    ."X-Mailer: PHP/" . phpversion());

if($mail)
{
echo 'OK';
}

}
else
{
echo '<div class="notification_error">'.implode('<br />', $error).'</div>'; 
}
}  
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:05:53+00:00Added an answer on June 13, 2026 at 7:05 am

    To generate a file using the form values, see this example.

    If You want to send an e-mail using php mail() with text and attachment, You have to mess a little bit with the headers. Add Content-Type: multipart/mixed; to the headers, see example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a plugin that uses the contact form 7 hook,
New to rails 3 I would like to create a contact form that people
I would like to create a form that allows users to contact our local
I have created a contact form which will email me once sent. Now I
I would like to create a windows form application, But I would like this
I am having one contact form in which I would like to add some
In my asp.net MVC 3 project I would like to create a contact that's
I would like to create a form and the validation_forms that would check if
i would like create a array of structure which have a dynamic array :
I would like to create this shape using just css. I am pretty sure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.