Note that there are some explanatory texts on larger screens.

plurals
  1. POError sending email with php script smtp.gmail Pear Centos
    text
    copied!<p>I read a lot of articles who explains how to send an email with smtp, like this <a href="https://stackoverflow.com/questions/712392/send-email-using-gmail-smtp-server-from-php-page">Send email using GMail SMTP server from PHP page</a> I have a cloud server and a localhost setup, both are the same (Centos 6, installed only httpd, php and mysql through yum). The iptables are the same: output ports opened, input only for 22 and 80.</p> <p>I installed pear Mail and pear Net_SMTP to use with smtp.gmail.com. phpinfo(); shows openssl is enabled.</p> <p>I am using this code:</p> <pre><code> &lt;?php require_once "Mail.php"; $from = "&lt;from.gmail.com&gt;"; $to = "&lt;to.yahoo.com&gt;"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; $host = "ssl://smtp.gmail.com"; $port = "465"; $username = "&lt;myaccount.gmail.com&gt;"; $password = "password"; $headers = array ('From' =&gt; $from, 'To' =&gt; $to, 'Subject' =&gt; $subject); $smtp = Mail::factory('smtp', array ('host' =&gt; $host, 'port' =&gt; $port, 'auth' =&gt; true, 'username' =&gt; $username, 'password' =&gt; $password)); $mail = $smtp-&gt;send($to, $headers, $body); if (PEAR::isError($mail)) { echo("&lt;p&gt;" . $mail-&gt;getMessage() . "&lt;/p&gt;"); } else { echo("&lt;p&gt;Message successfully sent!&lt;/p&gt;"); } ?&gt; &lt;!-- end of php tag--&gt; </code></pre> <p><em>At my localhost server the script worked and I received the email at my gmail account.</em> But at my cloud server, with the same script, I got this error: (with the debug)</p> <p><strong>ErrorFailed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: Permission denied (code: -1, response: )]DEBUG: Send: QUIT</strong></p> <p>I searched a lot and I saw some people saying that error occurr when the 465 port are blocked.</p> <p>So I review my iptables, my connections etc and the port 465 for OUTPUT is opened.</p> <p>I did a test using: <strong>openssl s_client -verify 0 -connect smtp.gmail.com:465</strong> and I got this result: </p> <pre><code>verify depth is 0 CONNECTED(00000003) depth=2 C = US, O = Equifax, OU = Equifax Secure Certificate Authority verify return:1 depth=1 C = US, O = Google Inc, CN = Google Internet Authority verify return:1 depth=0 C = US, ST = California, L = Mountain View, O = Google Inc, CN = smtp.gmail.com verify return:1 --- Certificate chain 0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=smtp.gmail.com i:/C=US/O=Google Inc/CN=Google Internet Authority 1 s:/C=US/O=Google Inc/CN=Google Internet Authority i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority --- Server certificate -----BEGIN CERTIFICATE----- MIIDWzCCAsSgAwIBAgIKFeQVggADAAA7NjANBgkqhkiG9w0BAQUFADBGMQswCQYD VQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAGA1UEAxMZR29vZ2xlIElu dGVybmV0IEF1dGhvcml0eTAeFw0xMTExMTgwMTU3MTdaFw0xMjExMTgwMjA3MTda MGgxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1N b3VudGFpbiBWaWV3MRMwEQYDVQQKEwpHb29nbGUgSW5jMRcwFQYDVQQDEw5zbXRw LmdtYWlsLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAuK+t5ZRq6c3K kWPwLuIcPa6DgiBURaQK9akP4OBoXKJ6bqYIQWsS4C3RgnOaGaDENadxHSNZ5Qpl Vqg2S54N54SM5OXwOq0NtrqdlbhgigB53TZouiJvnLDxxIexSOn2Gx1qyZF2z8Ii MoUhHuStWgW5YoOHje8z6K9xQdYkQp0CAwEAAaOCASwwggEoMB0GA1UdDgQWBBTs OL4jbtJ5l8B6/eoEvv30KEiTrjAfBgNVHSMEGDAWgBS/wDDr9UMRPme6npH7/Gra 42sSJDBbBgNVHR8EVDBSMFCgTqBMhkpodHRwOi8vd3d3LmdzdGF0aWMuY29tL0dv b2dsZUludGVybmV0QXV0aG9yaXR5L0dvb2dsZUludGVybmV0QXV0aG9yaXR5LmNy bDBmBggrBgEFBQcBAQRaMFgwVgYIKwYBBQUHMAKGSmh0dHA6Ly93d3cuZ3N0YXRp Yy5jb20vR29vZ2xlSW50ZXJuZXRBdXRob3JpdHkvR29vZ2xlSW50ZXJuZXRBdXRo b3JpdHkuY3J0MCEGCSsGAQQBgjcUAgQUHhIAVwBlAGIAUwBlAHIAdgBlAHIwDQYJ KoZIhvcNAQEFBQADgYEAQiMlHuQLRFqR10UsSg5WTNe3vagbdnBLAkdhvAf90B5a 9beBxJH2/ylTSIGfD2uceAqzcsQe6Ouy4C9r3rz86qA1dhdtIcPg6uoZb+E2qhE5 UaOJOPO4rHInX9kscBxh+baHbpBMh+ch6v5L8plss8hd0id8C4g10YKzwcgPYlQ= -----END CERTIFICATE----- subject=/C=US/ST=California/L=Mountain View/O=Google Inc/CN=smtp.gmail.com issuer=/C=US/O=Google Inc/CN=Google Internet Authority --- No client certificate CA names sent --- SSL handshake has read 1850 bytes and written 299 bytes --- New, TLSv1/SSLv3, Cipher is RC4-SHA Server public key is 1024 bit Secure Renegotiation IS supported Compression: NONE Expansion: NONE SSL-Session: Protocol : TLSv1 Cipher : RC4-SHA Session-ID: 55E90A8854BB04C962AB8AD7D231C89291E62B28EC93F4189CFD512B2EFD43B6 Session-ID-ctx: Master-Key: C454B3ED7E5C522B745F0E2EBF45BDEADFAD2CE29ECE945C1CA6EBA1629921577FEECFF968D896E39CF4E0057731CD26 Key-Arg : None Krb5 Principal: None PSK identity: None PSK identity hint: None TLS session ticket lifetime hint: 100800 (seconds) TLS session ticket: 0000 - 75 be ab 14 ff bf e3 74-61 4f 98 e6 ec 58 ae ab u......taO...X.. 0010 - 50 2f 20 f5 12 14 ae b5-11 dd 2c c1 9e 99 36 b1 P/ .......,...6. 0020 - 9a 66 5b 76 15 c8 0e 7f-07 ce ce e1 4c b3 f4 12 .f[v........L... 0030 - 38 c8 43 2d a2 c7 f9 62-17 4f da 82 4f 4b 12 93 8.C-...b.O..OK.. 0040 - af 31 9e d5 90 8d 3e 4c-06 d6 73 30 fb b6 95 80 .1....&gt;L..s0.... 0050 - 59 1c 65 e3 d3 51 2e a7-48 15 11 ba 9f 72 89 12 Y.e..Q..H....r.. 0060 - 9a 68 63 df 65 22 0f cb-60 b7 cf 3c b4 c6 f9 92 .hc.e"..`..&lt;.... 0070 - a0 c1 34 d7 06 31 97 ef-e6 8a bf b8 14 d9 72 b0 ..4..1........r. 0080 - 13 d9 dd df ce 48 a1 83-74 53 d6 fe b0 5a 53 a1 .....H..tS...ZS. 0090 - ee d0 9e b3 .... Start Time: 1335462088 Timeout : 300 (sec) Verify return code: 0 (ok) --- </code></pre> <p>So, I think the problem doesn't have relation with "blocked port". I also tried port 587...</p> <p>I sent a message for my host asking if the ISP could be blocking those ports and they told me they don't block any ports, the clients (me) have full control of the server.</p> <p>I don't know what more can cause this error and what I can do now. Maybe some configuration file I am not seeing.</p> <p><strong>Anyone have some advice to help me or suggest more test I can do to get more information of why I am getting that error and solve this problem?</strong></p> <p>thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload