如何在fedora上使用php邮件

如何在fedora上使用php邮件,php,email,fedora,Php,Email,Fedora,我正在用PHP5.2.6运行FedoraCore9。我想使用php-mail命令从表单发送一封简单的电子邮件 我是否需要将我的系统配置为smtp服务器?如果是这样的话,我必须装梨之类的东西吗 我听说pear是默认安装的。但是,当我转到/usr/lib/php/pear时,文件夹是空的 当我使用yum-install-php-pear安装pear时,没有可用的镜像 有人对使用哪种邮件服务有什么建议吗?如果它是默认安装的,我可以在哪里找到如何配置 谢谢! 乔 这是我正在使用的代码: <

我正在用PHP5.2.6运行FedoraCore9。我想使用php-mail命令从表单发送一封简单的电子邮件

我是否需要将我的系统配置为smtp服务器?如果是这样的话,我必须装梨之类的东西吗

我听说pear是默认安装的。但是,当我转到/usr/lib/php/pear时,文件夹是空的

当我使用yum-install-php-pear安装pear时,没有可用的镜像

有人对使用哪种邮件服务有什么建议吗?如果它是默认安装的,我可以在哪里找到如何配置

谢谢! 乔

这是我正在使用的代码:

    <?php

require_once('../class.phpmailer.php');
$mail = new PHPMailer(true);

$mail->IsSMTP();

try {
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  $mail->SMTPSecure = "tls";                 // sets the prefix to the servier
  $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
  $mail->Port       = "587";                 // set the SMTP port for the GMAIL server
  $mail->Username   = "joestestemail@gmail.com";  // GMAIL username
  $mail->Password   = "joeiscool";            // GMAIL password

  //This is the "Mail From:" field
  $mail->SetFrom('joestestemail@gmail.com', 'First Last');
  //This is the "Mail To:" field
  $mail->AddAddress('joe12345@mailcatch.com', 'John Doe');
  $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
  $mail->Body     = "Hi! \n\n This is my first e-mail sent through PHPMailer.";

  $mail->Send();
  echo "Message Sent OK<p></p>\n";
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!
}

?>

您可以使用。它附带了一个简单的安装程序,可以安装您所需的一切,几分钟内即可运行。

让邮件发送和运行的最简单方法是安装和配置postfix。您可以使用:

yum install postfix
并在此处查看文档:

http://www.postfix.org/docs.html

我强烈建议你使用图书馆来发送电子邮件

您可以将它与服务器自己的邮件服务或internet上的任何其他服务器(您的ISP、Gmail等)一起使用

要获得更好的想法,请访问他们的网站:

require_once('../class.phpmailer.php');
$mail = new PHPMailer(true); // the true param means it will throw exceptions on     errors, which we need to catch

$mail->IsSMTP(); // telling the class to use SMTP

try {
  $mail->Host       = "mail.yourdomain.com"; // SMTP server
  $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  $mail->Host       = "mail.yourdomain.com"; // sets the SMTP server
  $mail->Port       = 26;                    // set the SMTP port for the GMAIL server
  $mail->Username   = "yourname@yourdomain"; // SMTP account username
  $mail->Password   = "yourpassword";        // SMTP account password
  $mail->AddReplyTo('name@yourdomain.com', 'First Last');
  $mail->AddAddress('whoto@otherdomain.com', 'John Doe');
  $mail->SetFrom('name@yourdomain.com', 'First Last');
  $mail->AddReplyTo('name@yourdomain.com', 'First Last');
  $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
  $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';     // optional - MsgHTML will create an alternate automatically
  $mail->MsgHTML(file_get_contents('contents.html'));
  $mail->AddAttachment('images/phpmailer.gif');      // attachment
  $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
  $mail->Send();
  echo "Message Sent OK<p></p>\n";
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!
}
与:

$mail->Host = "smtp.gmail.com";

php邮件程序仍然需要sendmail设置正确吗?我发现测试时无法执行错误:/usr/sbin/sendmail。如果您没有或不想安装sendmail,可以将其配置为使用internet上的任何SMTP服务器。看看这个例子,您需要配置
$mail-IsSMTP()
然后
$mail->Host=“smtp.server.com”。如果你愿意,你甚至可以用GMail发送电子邮件。检查这个:顺便说一句,我建议使用你的主机/ISP/GMail邮件服务器,而不是设置一个。这对您的配置和维护来说就少了一件事。我设置为使用gmail,但我得到了一个错误:无法执行:/usr/sbin/sendmail。检查:试试这个。并确保从该页面中删除以前使用的
mail()
旧呼叫:)
$mail->Host = "'smtp.gmail.com";
$mail->Host = "smtp.gmail.com";