在您的域上配置一个电子邮件地址,用您在您的域me@mydomain.com
上新创建的电子邮件地址和以下脚本中的 Hotmail/Gmail id 替换。id@hotmailOrgmail.com
Your Name
还要在以下脚本中替换为您的姓名并在您的服务器上进行测试:
<?php
$myName = "Your Name";
$myEmailAddressonDomain = "me@mydomain.com";
$myPreferredEmailAddresson = "id@hotmailOrgmail.com";
$mail = $_POST['email_field'];
$clientName = $_POST['name_field'];
$subject = $_POST['subject_field'];
$text = $_POST['message_field'];
$headers = 'From: "$name" <$yourEmailAddressonDomain>'.PHP_EOL.'Reply-To: '.$_POST['mail'].PHP_EOL;
$to = '"$yourname" <$myPreferredEmailAddresson>';
$message = $text.PHP_EOL.PHP_EOL."---".PHP_EOL."From: ".$name." <".$mail.">";
/* Server-side form validations */
$err = "Error with ";
if (!checkLen($name)) {
$err.='Name';
} else if (!checkLen($mail) && !checkEmail($mail)) {
$err.='Email';
} else if (!checkLen($subject)) {
$err.='Subject';
} else if (!checkLen($text)) {
$err.='Message';
}
if (strlen($err)>11) {
echo $err.' field';
exit;
}
/* end validations */
elseif (mail($to, $subject,$message, $headers)) {
echo "<span style='color: #336600'>Your message has been sent.</span>";
} else {
echo "An error occurred, please try again.";
}
function checkLen($str,$len=1)
{
return isset($str) && mb_strlen(strip_tags($str),"utf-8") > $len;
}
function checkEmail($str)
{
return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
}
?>
该电子邮件将通过您域的电子邮件地址到达您的 Hotmail/Gmail 收件箱(或任何非垃圾邮件)文件夹。
注意:在收到的电子邮件中 单击回复将显示客户的电子邮件地址(正如我们在Reply-To
上面的标题中设置的那样)
进行适当的更改,您就可以开始了。