我正在使用php邮件文件发送邮件。但我收到错误。这是我的代码 和错误
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>');
}
?>
这一切都是错误
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
答案 0 :(得分:2)
<?php
include("Mail.php");
/* mail setup recipients, subject etc */
$recipients = "feedback@yourdot.com";
$headers["From"] = "user@somewhere.com";
$headers["To"] = "feedback@yourdot.com";
$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);
?>
答案 1 :(得分:1)
实际上没有在php.ini中注释掉extension = php_openssl.dll行 这只是我的代码中的问题
答案 2 :(得分:0)
您的php似乎未配置为使用SSL,与您的提供商联系或修改php.ini
(/etc/php.ini
)并启用它。