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

时间:2012-11-16 16:41:01

标签: linux sendmail

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

1 个答案:

答案 0 :(得分:1)

使用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>");
 }
?>