我有一个使用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
。它们托管在同一台服务器上。域名的差异可能是个问题吗?
答案 0 :(得分: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);
}
答案 1 :(得分:0)
某些主机关闭了服务器发送电子邮件的能力(因此无法从服务器发送垃圾邮件)。我先检查一下。