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
80 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
    article.

  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
    blogging.

  19. Inspiring story there. What occurred after? Good
    luck!

  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
    too.

    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.
    Cheers

  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 – http://www.youtube.com,

  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 (http://www.youtube.com)

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

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>