php - 如何将 php-pear 安装到 AWS EC2

标签 php amazon-ec2 pear

我是 Amazon EC2 的新手。 我正在尝试在我的亚马逊服务器上安装 php-pear。 但是我在下面遇到了一些错误 enter image description here

有人可以帮助我吗?

最佳答案

我今天早些时候在运行 PHP7 的 EC2 Linux 实例上安装了它,如下所示:

sudo yum install php7-pear

一旦安装:

pear install Mail
pear install Net_SMTP

然而,在那之后就不是小菜一碟了。我遇到了与 PHP7 和 Postfix 相关的 SMTP 设置相关的其他挑战,这为我的特定案例带来了一些困难,因为我想发送内联的 base64 编码图像,这显然是一个非常不寻常的案例,因为我找不到任何帮助它。但是,对于发送一个简单的电子邮件,您只需要以下代码:

require_once "Mail.php";
$from = "My Name <no-reply@example.com>";
$host = "smtp.example.com";
$port = "587";
$username = "user@example.com";
$password = "password";
$subject = "Some subject";
$headers = array('From' => $from, 'To' => $to, 'Subject' => $subject);
$body = "\r\n\r\n--" . $boundary . "\r\n";
$body .= "Content-type: text/plain; charset=\"iso-8859-1\"\r\n";
$body .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$body .= "This is the message body.";
$body .= "\r\n\r\n--" . $boundary . "\r\n";

$smtp = Mail::factory('smtp', array(
            'debug' => true,
            'host' => $host,
            'port' => $port,
            'auth' => true,
            'username' => $username,
            'password' => $password));

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

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

关于php - 如何将 php-pear 安装到 AWS EC2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38117382/

相关文章:

php - Yii 关系在查询中生成 GROUP BY 子句

php - 强制 Yii 2 在 ActiveRecord 模型保存上使用准备好的语句

javascript - 从需要授权的页面获取内容

node.js - 在 https 上从不同位置快速提供文件

php - Pear Mail "Unable to find class for driver smtp"找不到文件,就在那里

php - 为什么我的 js 脚本没有在 WordPress 中加载

powershell - 从我的本地计算机在 Amazon EC2 实例上远程执行 powershell 脚本

ssh - ssh 终止后保持服务器在 EC2 实例上运行

php - 请提供GraphicsMagick安装的前缀[autodetect]

c - PECL 安装失败