Discussion:
Unable to send email from phpmailer
(too old to reply)
CHANDRA SEKHAR
2015-06-02 18:20:57 UTC
Permalink
Hello everyone,
I am using Apache HTTP Server 2.4 as the web server and PHP version 5.5 My
machine is using Windows 7 enterprise edition which comes with
a Windows firewall. I am using Microsoft live essentails for anti-virus.

Thus I am using external SMTP server. I don't have IIS
installed in my computer nor do I have an SMTP server running.

I tried the PHP's mail(...) function but the function fails. It reports 1.SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (41609424)
2.The following From address failed: ***@divyasthali.org : Called Mail() without being connected Mail error: The following From address failed: ***@divyasthali.org : Called Mail() without being connected I searched the entire php.net sites but the exact
problem is not faced by anyone. ICould the incompatibility between Apache and PHP causing this?

Any help would be appreciated very much

it is the program

<?php

require_once('../class.phpmailer.php');
//include_once($_SERVER["DOCUMENT_ROOT"]."phpmailer/class.phpmailer.php")
define('GUSER', '***@divyasthali.org'); // GMail username
define('GPWD', '#######');
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer(); // create a new object
$mail->SetLanguage('en');
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}

if (smtpmailer('***@gmail.com', '***@divyasthali.org', 'phani', 'test mail message', 'Hello World!')) {
// do something
}
if (!empty($error)) echo $error;
?>


Any help would be appreciated very much

Regards
Chandrasekhar
8688249368
Heiko Richter
2015-08-02 03:15:11 UTC
Permalink
Post by CHANDRA SEKHAR
Hello everyone,
I am using Apache HTTP Server 2.4 as the web server and PHP version 5.5 My
machine is using Windows 7 enterprise edition which comes with
a Windows firewall. I am using Microsoft live essentails for anti-virus.
Thus I am using external SMTP server. I don't have IIS
installed in my computer nor do I have an SMTP server running.
I tried the PHP's mail(...) function but the function fails. It reports 1.SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (41609424)
problem is not faced by anyone. ICould the incompatibility between Apache and PHP causing this?
Any help would be appreciated very much
it is the program
<?php
require_once('../class.phpmailer.php');
//include_once($_SERVER["DOCUMENT_ROOT"]."phpmailer/class.phpmailer.php")
define('GPWD', '#######');
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer(); // create a new object
$mail->SetLanguage('en');
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}
// do something
}
if (!empty($error)) echo $error;
?>
Any help would be appreciated very much
Regards
Chandrasekhar
8688249368
Hi!

The default configuration of PHP expects it to run on Linux/Unix etc.,
not on Windows.

Therefor PHP doesn't use SMTP by default; it expects the system to have
a little application called sendmail. On any Linux-/Unix-Box you
normally have this little console program that sends your mail out to
the MTA.

As your Windows-Box doesn't have sendmail you have to configure PHP to
use SMTP. I took these lines from the well-documented php.ini file on my
Debian system.

But still, please don't just copy and paste but read the documentation:
http://php.net/smtp

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

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

; Add X-PHP-Originating-Script: that will include uid of the script
followed by the filename
mail.add_x_header = On

; The path to a log file that will log all mail() calls. Log entries
; include the full path of the script, line number, To address and
; headers.
;mail.log =
; Log mail to syslog (Event Log on Windows).
mail.log = syslog
#################################

Yours,
Heiko

Loading...