October 8th, 2013, 04:08 PM
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:
This is reasonable as I don't have sendmail installed on my desktop.
/BOARD18/php/emailPlayerID.php:0, referer: http://localhost/BOARD18/testbed/testEmail.html
sh: 1: /usr/sbin/sendmail: not found
Is there any way that I can test this program without having to install sendmail?
October 8th, 2013, 05:07 PM
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.
October 8th, 2013, 07:01 PM
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.
October 9th, 2013, 05:24 AM
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.
October 9th, 2013, 11:01 AM
I can only plead ignorance as my defense. Of those libraries that you mentioned above, which is the simplest?
Originally Posted by Jacques1
October 9th, 2013, 11:42 AM
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.
October 9th, 2013, 11:43 AM
Originally Posted by richpri
Comments on this post
October 11th, 2013, 02:44 PM
OK. I have been playing with PHPMailer for a couple of days now with no success.
Originally Posted by Jacques1
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.
October 11th, 2013, 02:52 PM
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.
October 13th, 2013, 07:38 PM
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.