473,387 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

form posting messages at times and failing at other times

I have some code for sending email from a form and it has some attachment

The problem is at times it sends and at other times it fails to send what could the issues be and how do i fix it here is a sample of the code

I will appreciate any help thanks in advance here is the code.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // Receiving variables
  4. $subject = "Barter Center";
  5. $to =  "mail@example.com";
  6. $pfw_ip= $_SERVER['REMOTE_ADDR'];
  7. $first_name = addslashes($_POST['first_name']);
  8. $last_name = addslashes($_POST['last_name']);
  9. $country = addslashes($_POST['country']);
  10. $address = addslashes($_POST['address']);
  11. $from = addslashes($_POST['from']);
  12. $product = addslashes($_POST['product']);
  13. $make = addslashes($_POST['make']);
  14. $model = addslashes($_POST['model']);
  15. $year_made = addslashes($_POST['year_made']);
  16. $value = addslashes($_POST['value']);
  17. $description = addslashes($_POST['description']);
  18.  
  19.  
  20.  
  21. // Obtain file upload vars
  22. $fileatt      = $_FILES['fileatt']['tmp_name'];
  23. $fileatt_type = $_FILES['fileatt']['type'];
  24. $fileatt_name = $_FILES['fileatt']['name'];
  25.  
  26. $headers = "From: $from";
  27.  
  28. if (is_uploaded_file($fileatt)) {
  29.   // Read the file to be attached ('rb' = read binary)
  30.   $file = fopen($fileatt,'rb');
  31.   $data = fread($file,filesize($fileatt));
  32.   fclose($file);
  33.  
  34.   // Generate a boundary string
  35.   $semi_rand = md5(time());
  36.   $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  37.  
  38.   // Add the headers for a file attachment
  39.   $headers .= "\nMIME-Version: 1.0\n" .
  40.               "Content-Type: multipart/mixed;\n" .
  41.               " boundary=\"{$mime_boundary}\"";
  42.  
  43.   // Add a multipart boundary above the plain message
  44.   $message = "This is a multi-part message in MIME format.\n\n" .
  45.              "--{$mime_boundary}\n" .
  46.              "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
  47.              "Content-Transfer-Encoding: 7bit\n\n" .
  48.               "Visitor's IP: $pfw_ip\n"
  49. . "first_name: $first_name\n"
  50. . "last_name: $last_name\n"
  51. . "country: $country\n"
  52. . "address: $address\n"
  53. . "from: $from\n"
  54. . "product: $product\n"
  55. . "make: $make\n"
  56. . "model: $model\n"
  57. . "year_made: $year_made\n"
  58. . "value: $value\n"
  59. . "description: $description\n\n";
  60.  
  61.   // Base64 encode the file data
  62.   $data = chunk_split(base64_encode($data));
  63.  
  64.   // Add file attachment to the message
  65.   $message .= "--{$mime_boundary}\n" .
  66.               "Content-Type: {$fileatt_type};\n" .
  67.               " name=\"{$fileatt_name}\"\n" .
  68.                       //"Content-Disposition: attachment;\n" .
  69.               //" filename=\"{$fileatt_name}\"\n" .
  70.               "Content-Transfer-Encoding: base64\n\n" .
  71.               $data . "\n\n" .
  72.               "--{$mime_boundary}--\n";
  73. }
  74.  
  75. // Send the message
  76. $ok = @mail($to, $subject, $message, $headers);
  77. if ($ok) {
  78.   echo "<p>Your product will be uploaded to the site shotly . </p>";
  79. } else {
  80.   echo "<p>Mail could not be sent. Sorry!</p>";
  81. }
  82.  
  83.  
  84. ?>
  85.  
Jun 16 '08 #1
1 1117
Atli
5,058 Expert 4TB
Are you getting any errors?
Try removing the @ from the mail function to see if that generates any helpful messages.
Jun 16 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: CK | last post by:
Hi all, I know this question is stupid. But i need some advice for this. I am trying to develop a website, which will allow the user send to order form to the admin email. I am planning to use the...
6
by: zzapper | last post by:
Hi, If I make a mistake designing a JavaScript Form Checker, ie get the name (or case) of a form Field wrong, JavaScript seems to default to immediately returning true and the form is submitted...
5
by: Tyler Style | last post by:
Hullo - looking for a little advice here. I have a form on a page in one domain submitting to a cgi in another domain. Weirdly, on some Windows XP systems, a form on the page fails to submit/post...
2
by: Robert Stearns | last post by:
I have a persistent but not consistent error occurring in db2 / php under apache running on two different servers. I rebuilt the database from the ground up, starting with creates and sequential...
10
by: NB | last post by:
Hi Some of my recent posts have been kind of monologues. I know that they are challenging and nobody may have any idea about them. However, I keep posting, take this NG as a record keeper for...
5
by: RC | last post by:
I have a form with three text boxes on it. I want the third text box to show the total of the values in the other two text boxes. The first box is named: BoxOne and I type the number 2 into it...
3
by: Brian Keating EI9FXB | last post by:
Hello again, I've already placed a few posts on this topic. This time i've a simple application that exhibits my problem, I've placed sample solution 8k on my website should anyone be interested...
13
by: deko | last post by:
I have a basic feedback form with a submit button. After the "send" button is clicked, I want the user to be redirected to a different page that says "Your message has been sent." How do I do...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.