PHP邮件联系表单 [英] PHP mail contact form
本文介绍了PHP邮件联系表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个预定义的联系表单,当我发送表单时,我试图与php邮件发件人Hower配对,我的电子邮件地址很好地收到了表单,但邮件的内容并没有出现。以下是详细信息:
联系表格
< ; h4 > 联系表格:< ; / h4 >
< 表格 id = contact-form < span class =code-attribute> method = post action = submit.php >
< fieldset >
< label > < 输入 名称 = 电子邮件 value = 电子邮件 onBlur = if(this.value =='')this.value ='Email' onFocus = if(this.value =='Email')this.value ='' / > < / label >
< label > < 输入 名称 = subject value = 主题 onBlur = if(this.value =='')t his.value ='主题' onFocus = if(this.value =='Subject')this.value ='' / > < / label >
< textarea onBlur = if(this.value =='')this.value ='Message' onFocus = if(this.value == '消息')this.value ='' > 消息< / textarea >
< div class = 按钮 >
< a href = # onClick = document.getElementById('contact- form')。reset() > 清除< / a >
< a href = # onClick = document.getElementById('contact-form')。submit() > 发送< / a >
< / div >
< / fieldset >
< / form >
提交表格
<? php
// 联系 subject
$ subject = $ Subject ;
// 详细信息
$ message = $ Message ;
// 邮件 sender
$ mail_from = $ Email ;
// form data
$ Subject = $ _ POST [' subject'];
$ Email = $ _ POST [' email'];
$消息 = $ _ POST [' message'];
// sumbission data
$ ipaddress = $ _ SERVER [' REMOTE_ADDR'];
$ date = date(' d / m / Y');
$ time = date(' H:i:s');
//发送 电子邮件 if 所有 ok
< span class =code-summarycomment> $ headers = 来自:$ Email 。 \\\\ n;
$ headers 。 =' 内容类型:text / html; charset = iso-8859-1' 。 \\\\ n;
// From
$ emailbody = < p>您已收到查询中的新消息表单在您的网站上。< / p>
< p>< strong>电子邮件地址:< / strong> {$ Email}< / p>
& lt; p>< strong>查询:< / strong> {$ Subject}< / p>
< p>< strong>消息:< / strong> {$ Message}< / p>
< p>此消息是从IP地址发送的:{$ ipaddress} {$ time}< / p><$ span> = ;
$ header = 来自:$ Email< $ Message> ;
< span class =code-summarycomment>
// 输入 您的 电子邮件 地址
< span class =code-summarycomment> $ to =' exemple@exemple.com' ;
$ send_contact = mail( exemple@exemple.com,新 查询,$ emailbody,$ headers);
// 检查, if 消息 已发送 至 您的 电子邮件 < span class =code-summarycomment>
// display 消息 我们 recived 您的 信息
if($ send_contact){
echo 我们 recived 您的 contact i信息;
}
else {
echo ERROR;
}
? >
测试帐户结果
您 已收到 a new message 来自 查询 表单 您的 网站。
电子邮件 地址: testtome @ test。 com
查询: Web service
消息:
此 消息 已发送 来自 IP < span class =code-leadattribute>地址: 101 。 229 。 203 。 44 04/01/2013 at 00:23:15
正如您所看到的消息内容是没有出现。请帮忙。
解决方案
subject =
主题 ;
// < span class =code-summarycomment>详细信息
消息 =
I have a predefined contact form that I m trying to pair with a php mail sender Hower when I sent the form, my email address received well the form but the content of the message doesn''t not appear. Below is the details:
Contact form
<h4>Contact Form:</h4>
<form id="contact-form" method="post" action="submit.php">
<fieldset>
<label><input name="email" value="Email" onBlur="if(this.value=='') this.value='Email'" onFocus="if(this.value =='Email' ) this.value=''" /></label>
<label><input name="subject" value="Subject" onBlur="if(this.value=='') this.value='Subject'" onFocus="if(this.value =='Subject' ) this.value=''" /></label>
<textarea onBlur="if(this.value=='') this.value='Message'" onFocus="if(this.value =='Message' ) this.value=''">Message</textarea>
<div class="buttons">
<a href="#" onClick="document.getElementById('contact-form').reset()">Clear</a>
<a href="#" onClick="document.getElementById('contact-form').submit()">Send</a>
</div>
</fieldset>
</form>
Submit form
<?php
// Contact subject
$subject ="$Subject";
// Details
$message="$Message";
// Mail of sender
$mail_from="$Email";
//form data
$Subject = $_POST['subject'];
$Email = $_POST['email'];
$Message = $_POST['message'];
//sumbission data
$ipaddress = $_SERVER['REMOTE_ADDR'];
$date = date('d/m/Y');
$time = date('H:i:s');
//send email if all is ok
$headers = "From: $Email" . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// From
$emailbody = "<p>You have recieved a new message from the enquiries form on your website.</p>
<p><strong>Email Address: </strong> {$Email} </p>
<p><strong>Enquiry: </strong> {$Subject} </p>
<p><strong>Message: </strong> {$Message} </p>
<p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";
$header="from: $Email <$Message>";
// Enter your email address
$to ='exemple@exemple.com';
$send_contact=mail("exemple@exemple.com","New Enquiry",$emailbody,$headers);
// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}
?>
Test account result
You have recieved a new message from the enquiries form on your website.
Email Address: testtome@test.com
Enquiry: Web service
Message:
This message was sent from the IP Address: 101.229.203.44 on 04/01/2013 at 00:23:15
As you can see the message content is not showing up. Please help.
解决方案
subject ="
Subject"; // Details
message="
这篇关于PHP邮件联系表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文