#1
  1. Old Fart
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Chicago
    Posts
    106
    Rep Power
    4

    How to use the PHP mail() function locally


    I am running a development platform in my UBUNTU 12.04 desktop. It is running Apache with PHP. I am attempting to write a PHP AJAX program that will send an email using the mail() function. When i test it locally i get the following error message:
    Code:
    /BOARD18/php/emailPlayerID.php:0, referer: http://localhost/BOARD18/testbed/testEmail.html
    sh: 1: /usr/sbin/sendmail: not found
    This is reasonable as I don't have sendmail installed on my desktop.

    Is there any way that I can test this program without having to install sendmail?
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    You can configure PHP to use gmail as the outgoing SMTP host, google for instructions.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    11
    Rep Power
    0
    Richpri,

    For all I know you may have specific reasons for not wanting to install sendmail.
    If it's a dread of a lengthy install, I just want you to know that it took me a total of 5 minutes to download, install, and configure sendmail on my machine.

    And there's the tiny test-mail program for your desktop.
    http://www.toolheap.com/test-mail-server-tool/
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    why do you use the mail() function, anyway? Nowadays, there are many, many excellent PHP mailer libraries like PHPMailer or Swift Mailer. You shouldn't use low-level functions like mail() unless you have a very good reason for fumbling with the raw headers.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  8. #5
  9. Old Fart
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Chicago
    Posts
    106
    Rep Power
    4
    Originally Posted by Jacques1
    Hi,

    why do you use the mail() function, anyway? Nowadays, there are many, many excellent PHP mailer libraries like PHPMailer or Swift Mailer. You shouldn't use low-level functions like mail() unless you have a very good reason for fumbling with the raw headers.
    I can only plead ignorance as my defense. Of those libraries that you mentioned above, which is the simplest?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,997
    Rep Power
    375
    i have dealth with phpmailer, if you download it, it gives you some sample code which you can just copy and paste and away you go.
  12. #7
  13. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by richpri
    Of those libraries that you mentioned above, which is the simplest?
    PHPMailer.

    Comments on this post

    • richpri agrees : Thanks a lot.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  14. #8
  15. Old Fart
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Chicago
    Posts
    106
    Rep Power
    4

    Unhappy


    Originally Posted by Jacques1
    PHPMailer.
    OK. I have been playing with PHPMailer for a couple of days now with no success.

    As a last resort, I ran the test_callback.php script after altering only the email addresses. No email was sent and the page filled with what looks like a hex dump of the two image files used by the test script.

    I also tried using the smtp option with no success.

    Do I need to set any Apache or php.ini parameters before using PHPMailer?
    Is there an up to date users guide anywhere?
    The ones I found seem to be for much earlier releases of PHPMailer and are not very helpful.
  16. #9
  17. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    PHPMailer doesn't require any special configuration. The official example already lists all relevant options.

    I think it would be best to post the actual code. Do you have any freemailer account (Gmail etc.) to use as a test host? Have you verified that the send() method actually gets called? The hex dump sounds like the whole script doesn't really work.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  18. #10
  19. Old Fart
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Chicago
    Posts
    106
    Rep Power
    4

    Smile


    I finally got it to work.

    The problem was the port number not being correct for STARTTLS.

    I added the following line to my code and all was well.

    php Code:
    $mail->Port = '587';

IMN logo majestic logo threadwatch logo seochat tools logo