繁体   English   中英

如何在不使用任何其他PEAR包或库的情况下通过PHP发送电子邮件?

[英]How to send Email through PHP without using any additional PEAR package or library?

我希望通过PHP发送电子邮件,而无需安装或配置任何PHP邮件服务器。实现此目的的方法是什么。

我总是使用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("name@yourdomain.com","First Last");

    $mail->SetFrom('name@yourdomain.com', 'First Last');

    $mail->AddReplyTo("name@yourdomain.com","First Last");

    $address = "whoto@otherdomain.com";
    $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!";
}

用这个

$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM