Jump to content

Did not receive any file attachment in thunderbird email


alphaboss

Recommended Posts

Hello everyone I am trying to see if I can receive multiple photos at once from my contact php form to my thunderbird email when I go to my contact php form I click choose files and I highlight the photos that I want to send then I submitted form with those photos that I chosen then I checked my thunderbird email and I did receive the email from the contact form submitted but did not receive any file attachment. I have included the php code from the contact form any idea as what might be problem for this any help and solutions is greatly appreciated thanks very much in advance.

<?PHP
/*
    Contact Form from HTML Form Guide
    This program is free software published under the
    terms of the GNU Lesser General Public License.
    See this page for more info:
    http://www.html-form-guide.com/contact-form/contact-form-attachment.html
*/
require_once("./include/fgcontactform.php");

$formproc = new FGContactForm();

//1. Add your email address here.
//You can add more than one receipients.

$to = $formproc->AddRecipient('test@alphaboss.ca'); //<<---Put your email address here
$subject = 'Form was submitted';
$message = 'New message from a visitor';
$headers = 'From: test@alphaboss.ca' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers); // 'test@alphaboss.ca', 'Form was submitted', 'New message from a visitor'

//2. For better security. Get a random tring from this link: http://tinyurl.com/randstr
// and put it here
$formproc->SetFormRandomKey('HG9hPBpn9Bn26yg');

$formproc->AddFileUploadField('photo','jpg,jpeg,gif,png,bmp',2024);
if(isset($_POST ['uploads']))
if(isset($_POST ['photo']))
if(count($_POST['uploads']['photo'])) {
    foreach ($_POST['uploads']['photo'] as $file) {
        
        //do your upload stuff here
        echo $file;
        
    }
}
if(isset($_POST['submitted']))
{
   if($formproc->ProcessForm())
   {
        $formproc->RedirectToURL("thank-you.php");
   }
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
     <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
     <title>Alpha Boss Computer Services</title>
<style>
body {font-family: Verdana, sans-serif;
margin: 0;
height: 1140px;
}
h1 {text-align:center;
    color: navy;
}
#background-image {
  background-image: url(alpha.png);
  width: 100%;
  top: 0;
  left: 0;
  height:1140px; 
  opacity: 0.2;
  position: absolute;
  background-repeat: repeat;
  padding: 0;
  margin: 0;
  z-index:0;
}
.navbar {
  overflow: hidden;
  background-color: #333;
  position: fixed;
  bottom: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.navbar a {
  display: inline-block;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
  margin: 0px auto;
}

.navbar a:hover {
  background: #f1f1f1;
  color: black;
}
 .fieldset-auto-width {
         display: inline-block;
}
form {
    position: absolute;
    z-index: 2;
    left: 50px;
    right: 50px;
    top: 195px;
}
div.b {
    line-height: 1.6;
}
</style>
     <link rel="STYLESHEET" type="text/css" href="contact.css" />
     <script type='text/javascript' src='scripts/gen_validatorv31.js'></script>
     <script type='text/javascript' src='scripts/fg_captcha_validator.js'></script>
     <link rel="icon" href="http://localhost/alpha.png" type="image/png" sizes="16x16">
</head>
<body>
<div id="background-image"></div>
<!-- Form Code Start -->
<div class="b"><h1>You can call <u>289-696-7530</u> or fill out the contact form below; for your computer, peripheral, and photo slideshow needs. Hours of operation: Monday to Friday 9AM to 5PM.</h1></div>
<div class="form"><center><form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' enctype="multipart/form-data" accept-charset='UTF-8'>
<fieldset class="fieldset-auto-width">
<legend><h1>Contact Form</h1></legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text'  class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
<div class='short_explanation'><font size="3" color="navy"><h1>* required fields</h1></font></div>
<div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
<div class='container'>
    <label for='name'><font size="3" color="navy"><h1>Your Full Name Below*:</h1></font></label><br/>
    <input style='width:400px;height:40px;font-size:14pt; border:3px solid black' type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br/>
    <span id='contactus_name_errorloc' class='error'></span>
</div>
<div class='container'>
    <label for='email'><font size="3" color="navy"><h1>Your Email Address Below*:</h1></font></label><br/>
    <input style='width:400px;height:40px;font-size:14pt; border:3px solid black' type='text' name='email' id='email' value='<?php echo $formproc->SafeDisplay('email') ?>' maxlength="50" /><br/>
    <span id='contactus_email_errorloc' class='error'></span>
</div>
<div class='container'>
    <label for='message'><font size="3" color="navy"><h1>Your Message Below:</h1></font></label><br/>
    <span id='contactus_message_errorloc' class='error'></span>
    <textarea rows="10" cols="50" name='message' id='message' style="border:3px solid black"><?php echo $formproc->SafeDisplay('message') ?></textarea>
</div>
<div class='container'>
    <label for='photo'><font size="3" color="navy"><h1>Upload your photos:</h1></font></label><br/>
    <input style='font-size:24px' type="file" name='photo[]' id='photo' multiple=""/><br/>
</div>
<div class='container'>
    <input style='font-size:24px' type='submit' name='Submit' value='Submit' />
</div>
</fieldset>
</form></center></div>
<div class="navbar">
<div class="navbar-inner">
<a href="index.html">HOME</a>        
<a href="https://www.facebook.com/Alpha-Boss-Computer-Services-1259286717548256/">FACEBOOK PAGE</a>
</div>
</div>
<!-- client-side Form Validations:
Uses the excellent form validation script from JavaScript-coder.com-->

<script type='text/javascript'>
// <![CDATA[

    var frmvalidator  = new Validator("contactus");
    frmvalidator.EnableOnPageErrorDisplay();
    frmvalidator.EnableMsgsTogether();
    frmvalidator.addValidation("name","req","Please provide your name");

    frmvalidator.addValidation("email","req","Please provide your email address");

    frmvalidator.addValidation("email","email","Please provide a valid email address");

    frmvalidator.addValidation("message","maxlen=2048","The message is too long!(more than 2KB!)");

    frmvalidator.addValidation("photo","file_extn=jpg;jpeg;gif;png;bmp","Upload images only. Supported file types are: jpg,gif,png,bmp");
// ]]>
</script>

</body>
</html>

Link to comment
Share on other sites

I don't think that I was perfectly clear with my question that I wanted to ask when it comes to uploading multiple files in php to be submitted to an email. For one line in my code which is: $formproc->AddFileUploadField('photo','jpg,jpeg,gif,png,bmp',2024); I am only adding one photo to this line. I want to change it so it is looping through the array of files and adding multiple photos instead. I am not to sure how to go about it though. Plus I also changed $_POST to $_FILES for my file type inputs. Any ideas of how to change it for the looping I hope that this clears up the question for you thanks in advance.

Link to comment
Share on other sites

If the thing you're using to process that form will accept an uploaded file array, then use that.  If it doesn't, your options are either to give each upload field a different name and process them individually, or have some PHP code that takes the incoming $_FILES array and rebuilds it to give the array unique names and then calls the attach method for each name.

Link to comment
Share on other sites

I updated the php code to make it loop through the array of files but still not received any attachment in email here is the updated code: 

<?PHP
/*
    Contact Form from HTML Form Guide
    This program is free software published under the
    terms of the GNU Lesser General Public License.
    See this page for more info:
    http://www.html-form-guide.com/contact-form/contact-form-attachment.html
*/
require_once("./include/fgcontactform.php");

$formproc = new FGContactForm();

//1. Add your email address here.
//You can add more than one receipients.

$to = $formproc->AddRecipient('test@alphaboss.ca'); //<<---Put your email address here
$subject = 'Form was submitted';
$message = 'New message from a visitor';
$headers = 'From: test@alphaboss.ca' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers); // 'test@alphaboss.ca', 'Form was submitted', 'New message from a visitor'

//2. For better security. Get a random tring from this link: http://tinyurl.com/randstr
// and put it here
$formproc->SetFormRandomKey('HG9hPBpn9Bn26yg');

$formproc->AddFileUploadField('photo','jpg,jpeg,gif,png,bmp',2024);
if(isset($_FILES ['name']))
if(isset($_FILES ['photo']))
if(count($_FILES['name']['photo'])) {
    foreach ($_FILES['name']['photo'] as $file) {
       if(isset($_FILES['submit'])){
 
 // Count total files
 $countfiles = count($_FILES['photo']['name']);

 // Looping all files
 for($i=0;$i<$countfiles;$i++){
  $file = $_FILES['photo']['name'][$i];
 
  // Upload file
  move_uploaded_file($_FILES['photo']['tmp_name'][$i],'submit/'.$file);
 
 }

        //do your upload stuff here
        echo $file;
        
    }
}
if(isset($_POST['submitted']))
{
   if($formproc->ProcessForm())
   {
        $formproc->RedirectToURL("thank-you.php");
   }
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
     <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
     <title>Alpha Boss Computer Services</title>
<style>
body {font-family: Verdana, sans-serif;
margin: 0;
height: 1140px;
}
h1 {text-align:center;
    color: navy;
}
#background-image {
  background-image: url(alpha.png);
  width: 100%;
  top: 0;
  left: 0;
  height:1140px; 
  opacity: 0.2;
  position: absolute;
  background-repeat: repeat;
  padding: 0;
  margin: 0;
  z-index:0;
}
.navbar {
  overflow: hidden;
  background-color: #333;
  position: fixed;
  bottom: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.navbar a {
  display: inline-block;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
  margin: 0px auto;
}

.navbar a:hover {
  background: #f1f1f1;
  color: black;
}
 .fieldset-auto-width {
         display: inline-block;
}
form {
    position: absolute;
    z-index: 2;
    left: 50px;
    right: 50px;
    top: 195px;
}
div.b {
    line-height: 1.6;
}
</style>
     <link rel="STYLESHEET" type="text/css" href="contact.css" />
     <script type='text/javascript' src='scripts/gen_validatorv31.js'></script>
     <script type='text/javascript' src='scripts/fg_captcha_validator.js'></script>
     <link rel="icon" href="http://localhost/alpha.png" type="image/png" sizes="16x16">
</head>
<body>
<div id="background-image"></div>
<!-- Form Code Start -->
<div class="b"><h1>You can call <u>289-696-7530</u> or fill out the contact form below; for your computer, peripheral, and photo slideshow needs. Hours of operation: Monday to Friday 9AM to 5PM.</h1></div>
<div class="form"><center><form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' enctype="multipart/form-data" accept-charset='UTF-8'>
<fieldset class="fieldset-auto-width">
<legend><h1>Contact Form</h1></legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text'  class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
<div class='short_explanation'><font size="3" color="navy"><h1>* required fields</h1></font></div>
<div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
<div class='container'>
    <label for='name'><font size="3" color="navy"><h1>Your Full Name Below*:</h1></font></label><br/>
    <input style='width:400px;height:40px;font-size:14pt; border:3px solid black' type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br/>
    <span id='contactus_name_errorloc' class='error'></span>
</div>
<div class='container'>
    <label for='email'><font size="3" color="navy"><h1>Your Email Address Below*:</h1></font></label><br/>
    <input style='width:400px;height:40px;font-size:14pt; border:3px solid black' type='text' name='email' id='email' value='<?php echo $formproc->SafeDisplay('email') ?>' maxlength="50" /><br/>
    <span id='contactus_email_errorloc' class='error'></span>
</div>
<div class='container'>
    <label for='message'><font size="3" color="navy"><h1>Your Message Below:</h1></font></label><br/>
    <span id='contactus_message_errorloc' class='error'></span>
    <textarea rows="10" cols="50" name='message' id='message' style="border:3px solid black"><?php echo $formproc->SafeDisplay('message') ?></textarea>
</div>
<div class='container'>
    <label for='photo'><font size="3" color="navy"><h1>Upload your photos:</h1></font></label><br/>
    <input style='font-size:24px' type="file" name='photo[]' id='photo' multiple=""/><br/>
</div>
<div class='container'>
    <input style='font-size:24px' type='submit' name='Submit' value='Submit' />
</div>
</fieldset>
</form></center></div>
<div class="navbar">
<div class="navbar-inner">
<a href="index.html">HOME</a>        
<a href="https://www.facebook.com/Alpha-Boss-Computer-Services-1259286717548256/">FACEBOOK PAGE</a>
</div>
</div>
<!-- client-side Form Validations:
Uses the excellent form validation script from JavaScript-coder.com-->

<script type='text/javascript'>
// <![CDATA[

    var frmvalidator  = new Validator("contactus");
    frmvalidator.EnableOnPageErrorDisplay();
    frmvalidator.EnableMsgsTogether();
    frmvalidator.addValidation("name","req","Please provide your name");

    frmvalidator.addValidation("email","req","Please provide your email address");

    frmvalidator.addValidation("email","email","Please provide a valid email address");

    frmvalidator.addValidation("message","maxlen=2048","The message is too long!(more than 2KB!)");

    frmvalidator.addValidation("photo","file_extn=jpg;jpeg;gif;png;bmp","Upload images only. Supported file types are: jpg,gif,png,bmp");
// ]]>
</script>

</body>
</html>

Are there any ideas as what I am doing wrong here and what to do to fix it?

Link to comment
Share on other sites

You still call $formproc->AddFileUploadField only once.  If that's the only way to add a file to the email, if the library you're using doesn't have a way to add an entire array of files, then you need to call that once per file to add each file with its own name.

Also, your code here will be a lot easier to read if you post it inside a code block.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...