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
。それらは同じサーバーでホストされています。ドメイン名の違いが問題になる可能性はありますか?