0

I m tryinng to send mail using following script. This scrips works fine if I execute this script in browser But if I run this script through command-line(cmd ) than getting smrp connection failed() error. code :

function sendMail($subject,$cc,$bcc,$emailcontent){
global $_mailmsg;
$emailcontent=$_mailmsg;
$mail = new PHPMailer;
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';  // Specify main and backup server
$mail->Port = '465';
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'username@gmail.com';                            // SMTP username
$mail->Password = 'XXXXXXXX'; 
$mail->SMTPSecure = 'ssl';
$mail->From = 'username@gmail.com';
$mail->FromName = 'Notification';
$mail->addAddress('abc@gmail.com');  // Add a recipient
$mail->addReplyTo('username@gmail.com');
if(!empty($cc)){    $mail->addCC($cc); }
if(!empty($bcc)){   $mail->addBCC($bcc);}   
$mail->WordWrap = 50;                                 // Set word wrap to 50 characters 
$mail->isHTML(true);                                  // Set email format to HTML
$mail->Subject = $subject;
$mail->Body    = $emailcontent; 
try
{
    if($mail->send()) {
        return 1;
       exit;
    }
    else
    {
              echo 'Mailer Error: ' . $mail->ErrorInfo;
       return 0;
    }
}
catch(Exception $e)
{
    return 0;   
}
}

I also config php.ini file

; For Win32 only.
; http://php.net/smtp
 SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 465
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = username@gmail.com

To run php file i wrote the following things in cmd

php filename.php
kreya
  • 1,091
  • 5
  • 24
  • 52
  • 1
    php CLI uses another ini file, perhaps this is the reason? – Ronni Skansing Jun 09 '14 at 09:24
  • which file is used by php CLI ?? – kreya Jun 09 '14 at 09:33
  • 1
    I would appreciate if you spend some time trying to find out first.. But here is a link http://stackoverflow.com/questions/2750580/how-to-find-the-php-ini-file-used-by-the-command-line check the accepted answer. – Ronni Skansing Jun 09 '14 at 09:34
  • @RonniSkansing : Thanks for reply. I checked it out this link and its make sense. File(php.ini) which I edited that was write file. – kreya Jun 09 '14 at 09:41

0 Answers0