3

Preview: I have been trying to send an email using Moodle for a long time and finally decided to test sending an email by using a standard PHP mail() function to test if mail is working fine.

BUT EVEN PHP DOES NOT SEND AN EMAIL!!

Problem Scenario:

This is my code for PHP:

$to = "receiver@gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "username150@gmail.com";
$headers = "From:" . $from;
ini_set( "sendmail_from", "username@gmail.com" ); 
ini_set( "SMTP", "smtp.gmail.com" );  
ini_set( "smtp_port", "25" );
ini_set("username","username0@gmail.com"); 
ini_set("password","password");
mail($to,$subject,$message,$headers);
echo "Mail Sent.";

The Error which I get is :

    Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 Must issue a STARTTLS                command first. sz6sm10013088pab.5 - gsmtp in C:\Program Files (x86)\Moodle\server\moodle\user\edit.php on line 252

I have tested my gmail server using Telnet and it is listening fine on Port 25. I have done everything that has been told by this error and other related posts

Tried: "ssl://smtp.gmail.com" but it would simply give the following error:

    Warning: mail() [function.mail]: Failed to connect to mailserver at  "ssl://smtp.gmail.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Program Files (x86)\Moodle\server\moodle\user\edit.php on line 252

even though openssl.dll has been uncommented in PHP.ini.

 ;extension=php_tidy.dll
 extension=php_xmlrpc.dll
 ;extension=php_openssl.dll;

Also, I have configured the php.ini file(php.ini-production and php.ini-development also):

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = username@gmail.com

But adding this to php.ini did not make much of a difference(therefore I resorted to set_ini()) as the server would coninue saying that "localhost smtp server cannot be configured on Port 25" though I had set the SMTP=smtp.gmail.com in php.ini.

Any help on this would be greatly appreciated. Thanks in advance.

tbdei
  • 31
  • 2
  • 5
  • Try with the PORT nº 465 or 587... See here: https://support.google.com/mail/answer/13287?hl=en – Eleazan Jul 17 '13 at 12:00
  • Thanks for your reply.Nah,not working.It is stuck on the same error. – tbdei Jul 17 '13 at 12:05
  • can you please check if openssl is correctly loaded by running phpinfo();? i had a similar issue with the openssl.dll a while back where one of the extensions i was using (php_exif if i remember correctly) was conflicting with the openssl extension – lePunk Jul 17 '13 at 12:08
  • are you in local machine ? – Ghilas BELHADJ Jul 17 '13 at 12:11
  • Thanks lePunk, where/what do I exactly lookup on running phpinfo()? – tbdei Jul 17 '13 at 12:20

1 Answers1

2

You've configured port 25 for the mail server.

The error message you're getting says that it's unable to connect to localhost:25.

Therefore you have two options:

  1. Install / Properly configure an SMTP server on localhost port 25
  2. Change the configuration to different port to which you can connect to:

.

  • Port for TLS/STARTTLS: 587
  • Port for SSL: 465

This support forum thread may be helpful.

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
  • Thanks for your reply mate. I went through the forum thread. I have a working smtp.gmail.com server listening on Port 25 and Port 587(which is required for TLS/STARTTLS). I have configured these settings in php.ini. – tbdei Jul 17 '13 at 12:11