如何通过 PHP 发送电子邮件而不使用任何额外的 PEAR 包或库?

发布于 2024-10-21 13:21:37 字数 57 浏览 2 评论 0原文

我想通过 PHP 发送电子邮件,而不安装或配置任何 PHP 邮件服务器。有哪些方法可以实现这一目标。

I want to send email through PHP without installing or configuring any PHP mail server.what are the ways to achieve this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

稚然 2024-10-28 13:21:37

我一直使用 PHP Mailer 类,这个类真的很容易使用,而且功能很强大。尝试一下。

您可以从这里下载它 PHP MAILER

这是一个示例

    require_once('../class.phpmailer.php');

    $mail             = new PHPMailer(); // defaults to using php "mail()"

    $body             = file_get_contents('contents.html');
    $body             = eregi_replace("[\]",'',$body);

    $mail->AddReplyTo("[email protected]","First Last");

    $mail->SetFrom('[email protected]', 'First Last');

    $mail->AddReplyTo("[email protected]","First Last");

    $address = "[email protected]";
    $mail->AddAddress($address, "John Doe");

    $mail->Subject    = "PHPMailer Test Subject via mail(), basic";

    $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

    $mail->MsgHTML($body);

    $mail->AddAttachment("images/phpmailer.gif");      // attachment
    $mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

    if(!$mail->Send()) {
      echo "Mailer Error: " . $mail->ErrorInfo;
    } else {


echo "Message sent!";
}

I always use the PHP Mailer class, this class is really easy to use, and so powerful. Give it a try.

You can download it from here PHP MAILER

Here's an example

    require_once('../class.phpmailer.php');

    $mail             = new PHPMailer(); // defaults to using php "mail()"

    $body             = file_get_contents('contents.html');
    $body             = eregi_replace("[\]",'',$body);

    $mail->AddReplyTo("[email protected]","First Last");

    $mail->SetFrom('[email protected]', 'First Last');

    $mail->AddReplyTo("[email protected]","First Last");

    $address = "[email protected]";
    $mail->AddAddress($address, "John Doe");

    $mail->Subject    = "PHPMailer Test Subject via mail(), basic";

    $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

    $mail->MsgHTML($body);

    $mail->AddAttachment("images/phpmailer.gif");      // attachment
    $mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

    if(!$mail->Send()) {
      echo "Mailer Error: " . $mail->ErrorInfo;
    } else {


echo "Message sent!";
}
墟烟 2024-10-28 13:21:37

使用此

$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";

请记住您无法通过本地主机发送电子邮件。当您的代码在线时,此功能将发送信息

Use this

$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";

Remember you cannot send email through localhost. This function will send information when your code is online

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文