gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 04:40:18 25 4
gpt4 key购买 nike

我是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com