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 に答える