Hello, I am a PHP newb, so try to bear with me as I lay out my problem.
Long ago, my boss wanted me to create a contact form for our website that would send an email to the boss and sales, so that customers could contact the company. Web development had a budget of $0, so, despite being a Windows only company, we were using Apache and PHP to try to do this. Our old (free) windows mail server worked using regular old PHP Mail(). It was also a crappy server, and eventually ground to a halt. IT decided to go with Google Apps email, which was much better.
Unfortunately, it also broke the web contact form.
So, I am trying everything I can to get this to work again. Web searches suggested fake Sendmail, so I tried that -- bashed my head in to try to get that working with no success. Later web searches suggested PHPMailer, so I tried that, and am currently bashing head in again.
I am getting the following error:
SMTP -> ERROR: Failed to connect to server: (0)
SMTP Error: Could not connect to SMTP host.
It would be one thing if this were one of the more descriptive errors, but alas.
Here are the settings I'm using in PHPMailer:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = '[Censored]';
$mail->Password = '[Censored]';
$mail->From = '[Censored]';
Here are the settings I'm using in PHP.ini:
[mail function]
; For Win32 only.
SMTP = smtp.gmail.com
smtp_port = 465
; For Win32 only.
sendmail_from = [Censored]
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path = "[Censored]\sendmail.exe -t"
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =
For reference of the things I have tried:
SSL was not configured right, I think this is now working, as PHPInfo() says that ssl is activated.
I have tried moving the port to 25, and 897
I have tried putting in a different SMTP address, got a different error message (that it couldn't find the host)
A ping to smtp.gmail.com goes through fine, as does a telnet to smtp.gmail.com 465
For laughs, I went in to the PHPMailer code, and tracked down the issue to this line (echos before it go through, echos after do not)
$this->smtp_conn = @fsockopen($host, // the host of the server
$port, // the port to use
$errno, // error number if any
$errstr, // error message if any
$tval); // give up after ? secs
$host is ssl://smtp.gmail.com
$port is 465
I am stumped at this point, do not know why fsockopen would not work using those settings, and yet telnet does?
Anybody have any OTHER ideas on how I can get a web form emailer to work using google apps email?