Sending emails, with a "from" field

Posted on 2006-05-26
Last Modified: 2008-02-26
i am using the following code:
function Email()
mail( $this->to, $this->subject, $this->message, "")
or print "could not send email";

unfortuantely the "from field deos not work, it just indicates on the recipients email the name of my host...
I want it to use the email address I have passed to it.

In an example I saw ages ago, but have since been unable to find, it seemed to alter the headers or something, but all the examples I have since found only use the example I show above....

Any clues..
Question by:jdav3579
    LVL 16

    Expert Comment

    "From: your name <>";

    you'd better use phpmailer and use smtp to send your mails, it is much more easier and reliable than mail() function

    Author Comment

    tried that, it just puts it in the body of the email!!! I am sure it was something to do with setting headers..
    with regard to phpmailer and smtp, I have never used this method before so am not sure how to used it.. i will google it though and have a look..
    LVL 16

    Accepted Solution

    get a copy of phpmailer, and it comes with an example file ready to go, just put your data instead of the sample data and here we go, a pullet proof mailing application :)
    LVL 49

    Expert Comment

    This should work,

    mail( $this->to, $this->subject, $this->message, "From:\r\n")

    Alternatively, as dr_dedo mentioned, you can download phpmailer from and use that class for your mail functionality. Please post back when you run into problems.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now