gpt4 book ai didi

linux - 需要使用不同 linux 服务器的 "sendmail"发送邮件(bash 或 php 脚本)

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:06:01 25 4
gpt4 key购买 nike

指定我们要连接以发送该邮件的 IP 地址的任何方法。?

最佳答案

使用 PHP 的 PEAR 库类 Mail .这真的很简单。

例子:(它使用带有 SMTP AUTH 的远程 SMTP 服务器,您不需要使用它)

<?php
require_once "Mail.php";

// mail data
$from = "You <sender@example.com>";
$to = "Her <recipient@example.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

// SMTP server info
$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";

// create mail headers
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject);

// create PEAR Mail object passing SMTP server info
$smtp = Mail::factory('smtp',
array (
'host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));

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

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

关于linux - 需要使用不同 linux 服务器的 "sendmail"发送邮件(bash 或 php 脚本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13420768/

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