LMSouq
moodle-core Open

Unable to Send Email Using PHP

TB
tbdei
1 month ago
3 views
Problem Description
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.

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base