与使用Pear和SMTP发送电子邮件相关的问题:无法连接套接字:fsockopen

时间:2017-10-27 06:46:01

标签: php email ssl smtp pear

我有一台服务器并尝试使用Pear和SMTP发送电子邮件。这是我的代码:

<?php
error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED ^ E_STRICT);
ini_set("include_path", '/home/example/php:' . ini_get("include_path") );
require_once "Mail.php";
$host = "ssl://mail.example.com";
$username = "info@example.com";
$password = "ABC@123";
$port = "465";
$to = "mymail@gmail.com";
$email_from = "info@example.com";
$email_subject = "Subject Line Here: " ;
$email_body = "whatever you like" ;
$email_address = "noreply@example.com";


$headers = array ('From' => $email_from, 'To' => $to, 'Subject' => $email_subject, 'Reply-To' => $email_address);
$smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $email_body);


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

安装了梨库并且路径正确。但是当我运行代码时。得到此错误:

  

无法连接到ssl://mail.example.com:465 [SMTP:失败   connect socket:fsockopen():无法连接   ssl://mail.example.com:465(未知错误)(代码:-1,响应:)]

不知道问题出在哪里。 openssl_dl启用。端口也在TCP_IN处打开。是ssl的任何问题。是否需要安装在我的域名或主机名上。如果是,那么请让我知道如何做到这一点。

0 个答案:

没有答案