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
100 comments on “Problem sending mail with PHP mail function
  1. Alex & Kath says:

    Hmm.. it appears like your blog deleted my first comment (it was super long) so I will
    just summarise what I submitted and say, I’m seriously enjoying your blog. I am also an newbie writer but I’m still
    new to everything. Do you have any tips for inexperienced blog writers?
    I’d genuinely appreciate it.

    my site – Alex & Kath

  2. Yes! Finally something about muscle mass gain per month.

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

  4. Excellent web site. Do you post more articles
    often. My wife and I honestly appreciated your blog post!

  5. Getting Conjoined sproul supplying Conjoining not
    seem to workplace well on the telephone. This is free-based in Punjab and mostly proofreaders you sustained accidental injury as a result of fetching or employing product?

    Back in the 90′s veterinary surgeons were troubled by consistent to pay $2 million to a erstwhile employee.

  6. It’s going to be finish of mine day, except before ending
    I am reading this enormous article to increase my knowledge.

  7. We stumbled over here from a different website and thought I may
    as well check things out. I like what I see so now i’m following you.
    Look forward to looking into your web page repeatedly.

  8. I read this post fully concerning the resemblance of most recent and
    previous technologies, it’s amazing article.

    Also visit my webpage … how to hack facebook account html

  9. Today, I went to the beach front with my children.
    I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She
    placed the shell to her ear and screamed. There was a hermit crab inside
    and it pinched her ear. She never wants to go back!
    LoL I know this is totally off topic but I had to tell someone!

  10. Hmm it appears like your site ate my first comment (it was
    extremely long) so I guess I’ll just sum it up what I
    submitted and say, I’m thoroughly enjoying your blog. I as well am an aspiring blog blogger but I’m still new to the whole thing.
    Do you have any recommendations for newbie blog writers?
    I’d really appreciate it.

  11. I read this paragraph fully regarding the difference of most recent and earlier technologies, it’s amazing

  12. I leave a response each time I like a article on a site or if I have something to contribute to the discussion.
    Usually it is a result of the sincerness communicated in the post I read.
    And after this article Problem sending mail with PHP mail function | Dotvoid – A PHP Company.
    I was actually moved enough to drop a thought ;) I actually do
    have a couple of questions for you if it’s allright. Is it simply me or do some of these responses come across like coming from brain dead individuals?
    :-P And, if you are posting on additional social sites, I’d like to keep
    up with you. Would you make a list the complete urls of all your shared pages like your Facebook page, twitter feed,
    or linkedin profile?

  13. Bernie says:

    Hi there, I found your site by means of Google at the
    same time as searching for a similar topic, your web site got here up, it looks good.
    I have bookmarked it in my google bookmarks.
    Hello there, simply changed into aware of your weblog thru
    Google, and found that it’s truly informative. I am going to be careful for brussels.
    I’ll be grateful for those who continue this in future.
    A lot of folks will likely be benefited from your
    writing. Cheers!

    Here is my website – ミュール 心細く制作 (Bernie)

  14. Please let me know if you’re looking for a article writer for your weblog.
    You have some really good posts and I believe I would be a good asset.
    If you ever want to take some of the load off, I’d really like to write some material for your blog in exchange for a link back to mine.

    Please blast me an email if interested. Thank you!sexy girl dancing streaptease

  15. Howdy! I could have sworn I’ve visited this web site before but after going through some of the posts I realized it’s new to me.
    Anyways, I’m definitely delighted I discovered it and I’ll be book-marking it and
    checking back frequently!

  16. Currently it seems like BlogEngine is the preferred blogging platform available
    right now. (from what I’ve read) Is that what you’re using on your blog?

  17. First off I would like to say great blog! I had a quick question which I’d like to ask if you do not mind.
    I was curious to know how you center yourself and clear your
    mind before writing. I’ve had trouble clearing my mind in getting my ideas out there.
    I truly do enjoy writing however it just seems like the first 10 to
    15 minutes are usually lost just trying to figure out how to begin.
    Any recommendations or hints? Thank you!

  18. hen houses says:

    This paragraph is in fact a pleasant one it assists new the web visitors, who are wishing for

  19. Inspiring story there. What occurred after? Good

  20. Heriberto says:

    Hi there, I desire to subscribe for this weblog to take newest updates, so where can i
    do it please help out.

  21. I always emailed this webpage post page to all my friends,
    for the reason that if like to read it then my contacts will

    Here is my website – 推薦 ウォーキングシューズ 専営店

  22. I know this if off topic but I’m looking into starting my own blog and was curious what all
    is needed to get setup? I’m assuming having a blog like yours would cost a pretty
    penny? I’m not very internet savvy so I’m not 100% sure.
    Any suggestions or advice would be greatly appreciated.

  23. Someone essentially lend a hand to make seriously
    articles I might state. That is the first time I frequented your website page and to this point?
    I amazed with the analysis you made to create this actual post extraordinary.
    Wonderful task!

  24. Felipe says:

    Hey! Do you use Twitter? I’d like to follow you if that would be okay.
    I’m absolutely enjoying your blog and look forward to new posts.

  25. Hello there! I could have sworn I’ve been to this site before but after browsing through
    many of the articles I realized it’s new to me. Anyhow, I’m definitely
    delighted I came across it and I’ll be bookmarking it and
    checking back regularly!

    Here is my web-site … 上品 クラッチバッグ 秋冬

  26. What is current industry best practice ‘ and what
    should vehicle manufacturers be thinking about for the future.
    Show here your appreciation and your excited disbelief that she or he got something you thought was so complicated
    to work. In addition to a number of Siri demos came the real news:
    Apple is integrating with several news companies,
    such as BMW, GM, Mercedes, Land Rover, Jaguar, Audi, Toyota,
    Chrysler and Honda.

    Here is my webpage: Csr racing hack –,

  27. web site says:

    It’s a person of the first and most located in depth simulation games every released, to
    allow for you to build and manage a city from this particular ground up.

    This precedent was likely set by Apple’s own pricing
    among music at .99 a song.

  28. Hi there mates, its fantastic post about cultureand fully defined,
    keep it up all the time.

  29. The Kitchenaid mixer is an additional kitchen appliance that accompany various functions which is utilized for mixing all sorts
    associated with elements whether or not thicker as well as slender.
    This means wanting to constantly learn more about fine foods and wines.
    It is not fun to try to clean bread dough off the bottom of a mixer.

    Take a look at my web blog: Ankarsrum Original (

  30. Whhy people srill use to read news papers whnen in this technological globe
    all is presented on web?

  31. read says:

    Link exchange is nothing else except it is just placing the
    other person’s website link on your page at suitable place and other person will also
    do similar for you.

  32. Nice info, but still i have the same issue with hostmonster. My code is working fine with the other server.
    please assist

  33. Heya! I just wanted to ask if you ever have any issues with hackers?
    My last blog (wordpress) was hacked and I ended up losing a few months of
    hard work due to no data backup. Do you have any methods to prevent hackers?

    My homepage … healthier teeth

  34. Hi there very cool web site!! Guy .. Beautiful ..
    Superb .. I’ll bookmark your web site and take the feeds additionally?
    I’m happy to search out so many helpful info here within the publish,
    we want develop extra techniques in this regard, thank you for sharing.
    . . . . .

    my web page las vegas nightclub

  35. Jeannette says:

    What a information of un-ambiguity and preserveness of valuable knowledge concerning unexpected emotions.

    my page: psn card online kaufen (Jeannette)

  36. You are so cool! I do not believe I have read a single thing like this before.

    So nice to discover someone with genuine thoughts on this topic.
    Seriously.. thank you for starting this up. This website
    is something that’s needed on the web, someone with
    a bit of originality!

    Take a look at my web page – gta 5 Money Cheat xbox 360

  37. For most up-to-date information you have to go to see web and on world-wide-web I found this site as
    a best web page for hottest updates.

    my page: no2 blast health

  38. Have you ever thought about writing an e-book or guest authoring on other websites?
    I have a blog based on the same topics you discuss and would really like
    to have you share some stories/information. I know my readers would enjoy
    your work. If you’re even remotely interested, feel free to send me an e-mail.

    my website: no2 blast scam

  39. rocket sky says:

    My brother recommended I would possibly like this blog.
    He was totally right. This submit actually made
    my day. You cann’t believe simply how a lot time I had spent for
    this information! Thank you!

    My website: rocket sky

  40. Situated in Rochester, New York, 5LINX has grown to be identified by many vacation companies for achievement and ideal want
    to the genuine home business possibility business.

    Very carefully profiling the present senior citizen control men and
    women is essential, because delegation will never be efficient
    if it’s presented to someone who is not in a position to utilizing the delegated powers efficiently.
    Punta Mita also shares the same latitude due to the fact Hawaiian Island destinations.

  41. Fantastic goods from you, man. I have understand your stuff previous
    to and you’re just too great. I actually like what you have acquired here, really like what you are stating and the way in which you say it.

    You make it enjoyable and you still take care of
    to keep it wise. I can’t wait to read far more from you.
    This is actually a terrific site.

    Here is my weblog: top three kitchen

  42. Wonderful blog! I found it while searching on Yahoo News. Do you have any
    tips on how to get listed in Yahoo News? I’ve been trying for
    a while but I never seem to get there! Thanks

    Feel free to visit my webpage למה לא לנסות כאן

  43. If some one needs to be updated with hottest technologies after
    that he must be pay a quick visit this web site and be up to date
    all the time.

  44. Pretty great post. I just stumbled upon your blog and wanted
    to mention that I have really enjoyed browsing your weblog posts.

    In any case I will be subscribing for your rss feed and I’m hoping
    you write once more very soon!

    Feel free to surf to my webpage; עיצוב אתרים מקצועי

  45. Hello this is kind of of off topic but I was
    wondering if blogs use WYSIWYG editors or if you have to manually code with HTML.
    I’m starting a blog soon but have no coding expertise so
    I wanted to get guidance from someone with experience.
    Any help would be enormously appreciated!

    Look at my blog; superior rectus muscle cranial nerve innervation

  46. I think that is among the such a lot important info for me.
    And i’m glad studying your article. But should statement on few common things, The web site taste is perfect, the
    articles is actually excellent : D. Just right process,

    my site – מנעולן עצמאי

  47. Write more, thats all I have to say. Literally, it seems
    as though you relied on the video to make your point.

    You clearly know what youre talking about, why waste your intelligence on just posting videos to your blog
    when you could be giving us something enlightening to read?

    Feel free to visit my webpage: floetrol polycrylic (

  48. filip watch says:

    My brother suggested I might like this web site. He used to be totally right.

    This post actually made my day. You cann’t believe simply how much time I had spent for this information! Thanks!

  49. hue vietnam says:

    Have you ever considered writing an e-book or guest authoring on other
    blogs? I have a blog centered on the same subjects you discuss and would love to have you share some stories/information. I know my audience would enjoy your
    work. If you’re even remotely interested, feel free to send me an email.

  50. Hello, every time i used to check weblog posts here in the
    early hours in the daylight, since i like to learn more and more.

    Visit my website pescador 12 kayak

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>