PHP mail function not working on my Mac OS/X Snow Leopard

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spizzi
Forum Newbie
Posts: 2
Joined: Mon Oct 25, 2010 1:42 pm

PHP mail function not working on my Mac OS/X Snow Leopard

Post by spizzi »

I am starting to learn PHP's mail() function and I am running into issues with the mail function.

Here's what I run into:

1. First, I am running everything on localhost so that I can test/sandbox my work. I do not have my own Internet domain name yet, it's all localhost.

2. My php.ini has been updated as follows:

Code: Select all

sendmail_path = "/usr/sbin/sendmail -t"
3. My actual lines of code in mail.php file looks like this:

Code: Select all

$toaddress = "myemailaddress@myemailaddress.com";
<- I omitted my real address so it doesn't show up on this forum but my real address is in the code.

Code: Select all

$fromaddress = "From: myemailaddress@myemailaddress.com";
<- I omitted my real address so it doesn't show up on this forum but my real address is in the code.

4. I run the html file (it is a simple feedback form that executes the mail.php file) in my localhost browser and submit the form. I get NO visible errors when I submit (i.e. it echoes the success response to my browser). HOWEVER, I am trailing the mail log in my Terminal and it shows that multiple "Operation timed out" responses. Additionally, my mailq file shows all of my 30 attempts to submit the email (i.e. 30 times that I clicked "send" in the html form).

5. I then used the following from scripts I could gather on the Internet, none of these worked either.

5a. Updated the hostconfig file by adding the following line:

Code: Select all

MAILSERVER=-YES-
5b. Updated variable myhostname in the file main.cf

Code: Select all

myhostname = example.yahoo.com
Then updated relayhost in main.cf and put in my smtp server name (in this example, it is google gmail).

Code: Select all

relayhost = smtp.gmail.com
5c. I also changed the SMTP port to 2525 in the php.ini file.

Saved my files, gracefully restarted Apache, reloaded postfix, opened up the Terminal and started my tail. Executed my html form (and subsequently the mail.php) and still get the "Operation timed out" response in the tail with all my attempts getting queued up in the mailq.

I am stuck -- all I want to do is experiment with the mail() function in PHP on my localhost Macbook Pro without actually sending email. Do I just need to go the distance and get a domain name with a mail server in order to try this? I have searched the internet and a lot of forums but have been finding that the people who asked the question have not received a response.

Many many thanks in advance!
spizzi
Forum Newbie
Posts: 2
Joined: Mon Oct 25, 2010 1:42 pm

Re: PHP mail function not working on my Mac OS/X Snow Leopar

Post by spizzi »

I got this to work. Such a simple fix, I can't believe I spent HOURS on this.
Post Reply