Rimjhim Ratnani
Rimjhim Ratnani

Reputation: 113

PHP Won't Send Mail using mail.php

i am sending a mail using php mail file.but i am getting error.this is my code and error

Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (code: -1, response: )]

<?php
@require_once "Mail.php";

$from = 'email';
$to = 'email';

 1. List item

$subject = 'Hi!';


$headers = array(

    'To' => $to,
    'Subject' => $subject,
    'from' => $from 
);

$smtp = @Mail::factory('smtp', array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => '465',
        'auth' => true,
        'username' => 'email',
        'password' => 'password'
    ));

$mail = @$smtp->send($to, $headers);

if (@PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
} else {
    echo('<p>Message successfully sent!</p>');
}

?>

this all error

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\xampp\php\pear\Net\SMTP.php on line 491

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\xampp\php\pear\Net\SMTP.php on line 265

Strict Standards: Non-static method PEAR::raiseError() should not be called statically, assuming $this from incompatible context in C:\xampp\php\pear\Net\SMTP.php on line 267

Upvotes: 2

Views: 162

Answers (3)

Pedro Lobito
Pedro Lobito

Reputation: 98961

it seems that your php isn't configured to use SSL, contact your provider, or edit your php.ini (/etc/php.ini) and enable it.

Upvotes: 0

Rimjhim Ratnani
Rimjhim Ratnani

Reputation: 113

actually didn't comment out extension=php_openssl.dll line in php.ini that is only problem in my code

Upvotes: 1

Gaurav Sinha
Gaurav Sinha

Reputation: 34

<?php 
include("Mail.php"); 

/* mail setup recipients, subject etc */ 
$recipients = "[email protected]"; 
$headers["From"] = "[email protected]"; 
$headers["To"] = "[email protected]"; 
$headers["Subject"] = "User feedback"; 

$mailmsg = "Hello, This is a test."; 

/* SMTP server name, port, user/passwd */ 
$smtpinfo["host"] = "smtp.mycorp.com"; 
$smtpinfo["port"] = "25"; 
$smtpinfo["auth"] = true; 
$smtpinfo["username"] = "smtpusername"; 
$smtpinfo["password"] = "smtpPassword"; 

/* Create the mail object using the Mail::factory method */ 
$mail_object =& Mail::factory("smtp", $smtpinfo); 

/* Ok send mail */ 
$mail_object->send($recipients, $headers, $mailmsg); 

?>

Upvotes: 2

Related Questions