-1

PHP Mail() 関数を利用した HTML フォームがあります。私が使用している SMTP サーバーは localhost であり、認証は必要ありません。

<form action="../../Scripts/fused.php" method="POST"><p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">
<p>Phone</p> <input type="text" name="phone">

<p>Request Phone Call:</p>
Yes:<input type="checkbox" value="Yes" name="call"><br />
No:<input type="checkbox" value="No" name="call"><br />

<p>Website</p> <input type="text" name="website">

<p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>

これがphpファイルです:

<?php

$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$call = $_POST['call'];
$website = $_POST['website'];
$message = $_POST['message'];
$formcontent = 'From: $name \n Phone: $phone \n Call Back: $call \n Website: $website \n Message: $message';
$recipient = 'hr@example.com';
$subject = 'Fused Enterprises Contact Form';

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <hr@example.com>' . "\r\n";
$headers .= 'Cc: dev@example.com' . "\r\n";

mail($recipient, $subject, $formcontent, $headers) or die("Error!");

echo "Thank You, the form has been submitted. Someone from the Team will contact you shortly." . " -" . "<a href='/Home/' style='text-decoration:none;    color:#1e90ff;'> Return Home</a>";

?>

PEAR メールを実装する必要はありますか? 私もそれを実装しようとしましたが、メールが届きません。失敗しているかどうかはわかりません。スクリプトが実行され、echo. 迷惑メールフォルダには行きませんでした。

サイトは (このスクリプトと共に) の下example.comでホストされていますが、電子メールは localhost と smtp サーバーを使用していますmail.example.com。それらは同じサーバーでホストされています。ドメイン名の違いが問題になる可能性はありますか?

4

2 に答える 2

1

HTMl形式でメールを送信するには、ヘッダーが最も重要です。このphp関数を使用してください..私はここでこのスクリプトを使用しています... http://ieeeaset.com/mailer/mailer.php

function htmlmail()
    {
        if (strtoupper(substr(PHP_OS,0,3)=='WIN')) { 
            $eol="\r\n"; 
        } elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')) { 
            $eol="\r"; 
        } else { 
            $eol="\n"; 
        }
        $recmail = $_POST['toemail']; // address where you want the mail to be send
        $sub = $_POST['subject']; //subject of email that is sent
        $mess = $_POST['message'];
        $pattern[0]="\'";
        $pattern[1]='\"';
        $replace[0]="'";
        $replace[1]='"';
        $mess=  str_replace($pattern, $replace, $mess);
        $headers = "From: [senders_email].$eol . 
        "MIME-Version: 1.0".$eol .
        "Content-type: text/html; charset=iso-8859-1";
            mail($recmail,$sub,$mess,$headers);
    }
于 2013-03-05T19:57:26.690 に答える
0

一部のホストは、サーバーが電子メールを送信する機能をオフにします(したがって、サーバーからのスパムは不可能です)。何よりもまずそれをチェックします。

于 2013-03-05T19:55:43.040 に答える