0

メールを正常に送信するお問い合わせフォームを受け取りました。

ここに抜粋があります:

$_POST['message'] = wordwrap($_POST['message'], 70);
mail ('myemail@test.com', $_POST['subject'], $_POST['message'] , $_POST['email']);
echo "<div class='registertext'>Your email was succesfully sent to a member of the administration team. Please wait 24 hours for as to reply and ensure you check your junk mail!<br />To login please click <a href='login.php'>here</a></div>";

私が抱えている問題は、メールが私のホストから送信されることです。指定したいメールではありません。どうすればこれを克服できますか?

4

2 に答える 2

0

メールヘッダーで指定できます。

$recipient = "recipient@test.com";
    $from      = "You@yoursite.com";
    $replyTo   = "You@yoursite.com";
    $subject   = "Hi!";
    $text      = "<p>This is a test!<p>";

    $headers = "MIME-Version: 1.0\r\n"
      ."Content-Type: text/html; charset=utf-8\r\n"
      ."Content-Transfer-Encoding: 8bit\r\n"
      ."From: =?UTF-8?B?". base64_encode([Your Name]) ."?= <$from>\r\n"
      ."Reply-To: $replyTo\r\n"
      ."X-Mailer: PHP/". phpversion();

    //send it!
    if (mail($recipients, $subject, $text, $headers, "-f $from")){
        echo "sent";
        } else {
           echo "did not send";
        };

しかし、スパムフィルターに捕まる可能性は十分にあります。この場合の最善の策は、SMTPメールを処理し、実際のアカウントを使用してメールを送信するPHPメールライブラリを使用することです(これを処理できるパッケージはいくつかあります。PearMailPHPMailerなどです。

于 2012-12-06T21:14:25.043 に答える
0

SMTPアカウントを使用するPEARメールを使用できます。これが私が使っているメールフォームのコードです

        $from = "Name <webmaster@domain.com>";
        $to = "Name <address@domain.com>";
        $subject = "Subject";
        $body = 'A message!';

        $host = "ssl://domain.com";
        $port = "465";
        $username = "username";
        $password = "password";

        $headers = array ('From' => $from,
                          'To' => $to,
                          'Subject' => $subject);
        $smtp = Mail::factory('smtp',
                              array ('host' => $host,
                                     'port' => $port,
                                     'auth' => true,
                                     'username' => $username,
                                     'password' => $password));

        $mail = $smtp->send($to, $headers, $body);

        if (PEAR::isError($mail)) {
            echo("<p>" . $mail->getMessage() . "</p>");
        } else {
            echo("<p>Message successfully sent!</p>");
        }
于 2012-12-06T21:16:36.753 に答える