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
128 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
    up.

  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?
    Thanks!!

  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.

  12. And afterwards they had Uncle Tom’s Christmas pudding.

  13. fposn.pl says:

    It is in reality a nice and helpful piece of information. I am glad that
    you simply shared this helpful information with us.
    Please keep us up to date like this. Thank you for sharing.

  14. Good article. I definitely love this site.

    Continue the good work!

  15. hey there and thank you for your information – I have certainly picked up anything new
    from right here. I did however expertise several technical points using this
    web site, since I experienced to reload the website a lot of times
    previous to I could get it to load correctly. I had been wondering if your web host is OK?
    Not that I am complaining, but slow loading instances times will very frequently affect your placement in google and
    could damage your high quality score if ads and marketing with
    Adwords. Anyway I’m adding this RSS to my e-mail and
    can look out for much more of your respective exciting content.
    Make sure you update this again very soon.

  16. Hmm it looks like your site ate my first comment (it was super
    long) so I guess I’ll just sum it up what
    I wrote and say, I’m thoroughly enjoying your blog.
    I too am an aspiring blog writer but I’m still new to the whole thing.
    Do you have any tips and hints for inexperienced blog writers?

    I’d genuinely appreciate it.

    My webpage best thermogenic supplement for women

  17. Having read this I believed it was very enlightening.
    I appreciate you finding the time and effort to put this information together.
    I once again find myself personally spending a significant amount of time
    both reading and leaving comments. But so what,
    it was still worth it!

  18. This is my first time visit at here and i am truly
    impressed to read everthing at one place.

  19. What’s up every one, here every person is sharing these kinds of experience, thus it’s fastidious to read this webpage, and I
    used to pay a visit this webpage every day.

  20. Danielle says:

    There is definately a lot to find out about this topic.
    I really like all the points you made.

  21. The price of solar panels is certain to stay high due to the decrease quantity of manufacturing.
    The solar panels in your home require an preliminary investment that’s high but, think about
    some calculations relating to the rising price of energy and the advantage of the panels in the long term.
    This article will look more intently at solar powered
    heating of water and maintaining buildings heat. A
    photo voltaic scorching water heating system consists of a photo voltaic collector and a holding tank.

  22. Thanks for the marvelous posting! I quite enjoyed reading it, you
    could be a great author.I will ensure that I bookmark your blog and will
    often come back in the future. I want to encourage you to continue your great writing, have a nice afternoon!

  23. Just wish to say your article is as amazing. The clarity to
    your submit is just excellent and that i could think you’re knowledgeable on this subject.
    Fine with your permission allow me to clutch your feed to stay up to date with coming near
    near post. Thanks one million and please keep
    up the rewarding work.

  24. Thank you for another informative web site. The place else may just I am getting that
    type of info written in such a perfect manner? I have a undertaking that I am just now
    operating on, and I have been at the glance out for such information.

  25. Hi I am so thrilled I found your weblog, I really found you
    by error, while I was searching on Google for something else, Nonetheless I am here
    now and would just like to say thank you for a marvelous post and
    a all round thrilling blog (I also love the theme/design), I don’t have time to read it all at the
    moment but I have book-marked it and also included your RSS feeds, so when I have time I will be back to read much more, Please do
    keep up the fantastic job.

  26. Good day I am so lad I found your blog page, I really found you bby error, wile I was researching on Digg for something else, Nonetheless I am here now and would just like tto
    say thanks for a tremendous post and a all round thrilling blog
    (I alsdo lobe thhe theme/design), I don’t have time to look over it all at the minute but I have book-marked itt and also added your RSS
    feeds, so when I have time Iwill bee back to read
    more, Please do keep up the great job.

    My blog: water supplies, myhealthydrinksandsmoothies.hpage.com,

  27. Hello to every one, the contents existing at this web page are truly awesome for people experience, well, keep up the good
    work fellows.

  28. Red says:

    If some one wants to be updated with newest technologies therefore he must be
    pay a quick visit this site and be up to date daily.

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>