Problem sending mail with PHP mail function

Occasionally I have had trouble sending emails using the builtin mail() function in PHP. Sometimes emails never reached their intended destination. Naturally I have assumed that there might be a problem with some spam filters used. However, lazy as I am, I have not given it a second thought. Instead I have used a PHP class that allows me to send emails using a remote smtp server using an account on that dedicated server. This has been a good solution for my setup anyways. A few days ago a friend of mine was asked to investigate the very same problem for a client.

The problem seems to be that PHP use the ini directive sendmail_from to set the from email address in the SMTP protocol. If this is not correctly set, or if it does not match the from header in the email headers, the email is caught by spam protection software.

The simplest solution is to set the directive during execution:

ini_set("sendmail_from", $email_from);

$headers = "From: $email_from";

mail($to, $subject, $message, $headers);

The problem as well as the solution was already known by others. The operating system this time was windows and I know there are differences in the implementation between the windows and linux version of mail(). I am not sure if the problem exist on both platforms.

Still I bet there are lots of people out there with this problem without them knowing it. It could be a good idea to include more detailed information about this ini entry and its implications in the actual mail() documentation. Sending emails from web pages is, to say the least, a very common task.

Tagged with:
Posted in PHP
111 comments on “Problem sending mail with PHP mail function
  1. Lydia says:

    Wonderful, what a website it is! This website presents useful data to us, keep it

  2. Follopw the updates and undrstand the Google algorithm and acclimatize the changes
    instantaneously. Inlinme weight forward spinner baits for
    sauger and walleye tipped with nightcrawlers. A vinyl
    recording can give you a sound that is wholly different from the bits and
    bytes of a CD – not to mention a ladger case where the cover art and liner notes can be easily read by
    those of us noo longer in ouur 20′s.

    Here is mmy webpage: spinner chief review

  3. Very quickly this web page will be famous amid all blog viewers, due to it’s
    good articles or reviews

  4. Hi it’s me, I am also visiting this site daily,
    this web page is in fact nice and the visitors are genuinely sharing pleasant thoughts.

    My webpage; carte psn gratuit

  5. Chong says:

    In an exceedingly few individuals, such as for example infants or people who have impaired immune techniques herpes can pass on to
    affect multiple organs.

  6. Oh my goodness! Awesome article dude! Thank you, However I am encountering problems with
    your RSS. I don’t know why I cannot join it.

    Is there anybody having identical RSS problems?
    Anyone that knows the answer will you kindly respond?

  7. Hello there! This is kind of off topic but I need some guidance from an established
    blog. Is it difficult to set up your own blog? I’m not very techincal but I can figure things out pretty fast.
    I’m thinking about making my own but I’m not sure where to start.
    Do you have any ideas or suggestions? Many thanks

  8. Batteries are also still becoming smaller and more versatile in their application. They did,
    however, have 4 D holders, and two of those could be connected in series for the requisite
    12 volts. They aare used inn headlights, hand lamps, spots,
    torches, penlight and other similar appliances.

    Here is my site: jackery giant 10400mah laptop reviews

  9. Proxy Bay says:

    We would like to offer you valuable information about how to build up an ability of energetic healing and
    manage yourself, your relatives, pets, as well as your
    environment on the energetic level. The gems from where rays don’t fall would
    be the graces that souls forget to ask. Due towards the extreme speeds in the network, the server accomplishes the
    1:1 ratio in the relatively short time.

  10. Undeniably consider that that you said. Your favourite
    justification appeared to be on the net the simplest factor to
    be aware of. I say to you, I definitely get annoyed whilst other folks
    consider worries that they just do not realize about. You managed
    to hit the nail upon the top and also defined out the entire thing without having side-effects , people can take
    a signal. Will probably be again to get more. Thank you

  11. They both expand and harden the same, as well as taking the shape of
    whatever it is filling. In addition, Ultra Bond-100™ can also adhere to many inorganic substrates
    with the use of SPI’s AE-4™ adhesion enhancer additive.
    Houston based Lapolla Industries in July 2011 achieved the European Technical Approval
    (ETA) and CE Marking for its low density
    open cell spray foam insulation.

3 Pings/Trackbacks for "Problem sending mail with PHP mail function"
  1. [...] Problem sending mail with PHP mail function (tags: php mail) [...]

  2. [...] web hosting companies do not have the right configuration for php mail. There may not always be a simple solution, and this can be quite frustrating. But what [...]

  3. [...] al script y utilizando php moví el script al servidor 13 veces). Finalmente, como se explica aqui, hay que inicializar la dirección desde donde se envía el correo en forma explícita en php. La [...]

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>