-1

PHP アプリケーションからメールを送信しようとしています。以下は私のコードです。

    <?php
    error_reporting  (E_ALL);
    ini_set ('SMTP', 'smtp.live.com');
    ini_set ('smtp_port', '587');
    ini_set ('sendmail_from', 'mymail@hotmail.com');

    $to = "urmail@hotmail.com";
    $subject = "Test mail";
    $message = "Hello! This is a simple email message.";

    $headers = "From:mymail@hotmail.com\r\n";
    $headers .= "X-Mailer: php\r\n";
    $headers .= "Reply-To:mymail@hotmail.com\r\n";
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $result = mail($to,$subject,$message,$headers);
    if($result)
    {
   echo "Mail Sent.";
    }
    else
    {
   echo ("error");
    }
   ?>

「メールが送信されました」というメッセージが表示されるので、メールを受け取ることを期待しています...しかし、そうではありません。メールの受信が遅れる可能性があると仮定して、現在3日間待ちました. ジャンクもチェックしましたが、何もありません...だから、私のコードはメールを送信していないと思います....理由はわかりません。

一部の設定が抜けている可能性があります... しかし、PHP メールを使用するのはこれが初めてなので、どの設定が抜けているかわかりません。メールのドキュメントを読んだ後...そのような要件/設定が見つかりませんでした。どんな助けでも本当に感謝しています。

4

2 に答える 2

0

PHPMailer lib を使用してもかまわない場合は、次を試してください。

<?php
    require("PHPMailer_5.2.4/class.phpmailer.php");

    $mail = new PHPMailer();
    $mail->SMTPDebug = true;
    $mail->IsSMTP();  // telling the class to use SMTP
    $mail->SMTPAuth   = true; // SMTP authentication
    $mail->Host       = "StartTLS://smtp.live.com"; // SMTP server
    $mail->Port       = 587; // SMTP Port
    $mail->Username   = "username"; // SMTP account username
    $mail->Password   = "xxx";        // SMTP account password

    $mail->SetFrom('from_emailid', 'yourname'); // FROM
    $mail->AddReplyTo('replyto_emailid', 'name'); // Reply TO

    $mail->AddAddress('recepeint_emailid'); // recipient email

    $mail->Subject    = "First SMTP Message"; // email subject
    $mail->Body       = "Hi! \n\n This is my first e-mail sent through live SMTP using PHPMailer.";

    if(!$mail->Send()) {
      echo 'Message was not sent.';
      echo 'Mailer error: ' . $mail->ErrorInfo;
    } else {
      echo 'Message has been sent.';
    }
于 2013-09-26T09:08:42.440 に答える