Php.ini and mail();

Hello,
I am having an issue. Recently, I built a site on my MacBook Pro, running Mac OS 10.6.8. I installed MAMP Server to test my scripts. My scripts work and function the way they should. When I call the mail(); function, using MAMP, an email is sent to the specified user. NOTE: I configured MAMP’s php.ini file as such:

[mail function]
; For Win32 only.
SMTP = smtp.gmail.com
smtp_port = 25

; For Win32 only.
sendmail_from = me@gmail.com

Here is the code I am currently using:


mail($mailto, $mailsubject, $mailmessage, $headers) or die("Your message was not sent");

NOTE: When using MAMP, the email message is sent and I never encounter “Your message was not sent.”

Recently, I installed a Windows XP virtual machine on my MacBook Pro. I installed WAMP server. When I modified WAMP’s php.ini file to reflect the settings in MAMP, which are:

[mail function]
; For Win32 only.
SMTP = smtp.gmail.com
smtp_port = 25

; For Win32 only.
sendmail_from = me@gmail.com

An email message is NOT sent, and I do encounter “Your message was not sent” every time.

Any ideas?!?!

Gmail does not allows SMTP through port 25 as it’s insecure. I believe you need to enable SSL & use port 995.

Also, MAMP is probably not working because the mail function on it is for Win32 (AKA 32 bit windows) only, thus it’s probably sending to localhost hence the lack of an error.

I have to disagree with some of your statement. Prior to modifying the php.ini file, where it says “for Win32 only” an email message was not being sent by PHP. I am enrolled in one of SitePoint’s online classes. I posted a question in the class’s forum, asking how to modify php.ini, so I could send mail using MAMP. The instructor told me how to modify php.ini. Prior to modifying php.ini, I was not able to use the mail function. However, after I modified php.ini, I was able to use the mail function and an email was sent.

How do I enable SSL? Do I need to buy an SSL certificate? Or is there something in the php.ini file that needs to be enabled?

You said you could send mail via MAMP, so SSL is obviously not the issue here (and you don’t want to go down that rabbit hole, trust me).

It seems to me the problem is that you’re not giving any credentials (username/password) to the gmail server, which is why it won’t let you log in. Now, why this does work on the mac is beyond me (but then, I’m not very familiar with how they work). Unfortunately, there are no settings in php.ini to set a username and password for smtp (don’t ask me why, I’m stumped about that one too. They probably thought it would be a security risk or something).

What you could try is to use the SMTP server of your ISP. Most IPS don’t user/pass protect those, but simply allow access to anyone in their own network. If that doesn’t work you could set up a local SMTP server (not very easy), or use something like SwiftMailer to send your emails.

As as an alternative you could download and install this program papercut (free), set smtp to localhost in your php.ini, and just have all email arrive in this program, where you can also view the raw text sent over the pipe. Very handy for debugging, plus you no longer have these awkward “hm, didn’t it send the mail, or is the mail still on its way? Or did it end up in my spam box maybe? Or perhaps it was sent to somebody else?” moments :slight_smile:
HTML view is not very good though, but good enough for testing (I think it’s based off an old IE version)