-1

I have a form on a webpage which emails the details using the PHP mail() function. The form is quite long, and I also am including HTML formatting for the email.
The email sends fine if I don't include all the form information, but when I try to include the whole form the email doesn't get sent. It seems to stop working when I'm including too much information. As soon as I take some of the information out it works again, and it doesn't matter which part of the information I remove.
I have tried the form on two different website hosts with the same problem. The content for the email is only about 300 lines long so I'm not sure if size is the issue.

Does anyone know what might be causing the problem?

here is my code for your reference

When I say "stop working" above, I mean simply that the mail() function returns false and does not send the email. The actual form works fine.

Sandip Armal Patil
  • 6,241
  • 21
  • 93
  • 160
Ben
  • 897
  • 2
  • 16
  • 34
  • 2
    Wow, that is long indeed. Can you post just the relevant bits in your question? – Fluffeh Sep 28 '12 at 11:45
  • your code provided in link is too long – NullPoiиteя Sep 28 '12 at 11:49
  • thats gotta be a server setting some limit of characters or something, the fact that you can take out any part leads me to believe it is not code based – mcgrailm Sep 28 '12 at 11:50
  • *"It doesn't work"* [doesn't explain the problem](http://stuck.include-once.org/#help3) enough. You need to elaborate on your input, expected and actual outcomes, or concretise error messages. – hakre Sep 28 '12 at 11:55

2 Answers2

1

When you come to that amount of HTML within a PHP-script it is useful to catch it in a variable instead of putting every single line in a $body variable.

ob_start();
?>
<html>
   Your HTML.
</html>
<?
$body = ob_get_clean();

This way you can easier see if there is something wrong with your message ruining the mail-function.

Undrium
  • 2,558
  • 1
  • 16
  • 24
  • Hi Undrium, many thanks, I tried your suggestion and it solved my problem. The email is now being sent with all of the content included. – Ben Sep 28 '12 at 12:48
1

Here is a description of the php mail function. This document along with this document, What is the PHP Mail Character Limit, specifies that each line of the body must be no longer than 70 characters.

This stackoverflow, What is the maximum length of a string in PHP, as well as other sources indicate that PHP does not have a specific limit other than total memory limits which your string appears to be well under.

Also there are several different places where there could be a failure and you do not specify the behavior you are seeing for a failure.

First of all, check the return value of mail() to determine if PHP was able to hand the message off to the mail agent, the MTA. Next make sure that you specify good to and return addresses so that if there is a problem in the mail agent, it will be able to send you some kind of a reply describing the problem.

An elaboration of the answer provided by Undrium above. Here are some links to additional materials based on his answer.

Here is the ob_get_clean() documentation.

Here is an example using ob_get_clear() with sending HTML Email.

Community
  • 1
  • 1
Richard Chambers
  • 16,643
  • 4
  • 81
  • 106
  • Hi Richard, thank you very much for your answer. I checked the return value of mail() and it is false. I also checked the to and return addresses and they are good. What I mean by the behaviour I am seeing for a failure is when the mail() returns false and does not send the email. – Ben Sep 28 '12 at 12:28
  • If the mail() function is returning false then the mail was not accepted for delivery. That implies that there is a problem with the mail message and it is being rejected by the MTA. Do you have documentation on the limits of your MTA? As an example, here is a configuration guide for Zimbra. http://wiki.zimbra.com/wiki/Configuring_maxmessagesize – Richard Chambers Sep 28 '12 at 12:48