1

有什么方法可以指定我们要连接的 IP 地址以发送该邮件。?

4

1 回答 1

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>");
 }
?>
于 2012-11-16T17:27:23.793 回答