我使用下面的脚本将包含已提交字段的电子邮件返回到我的电子邮件地址。
我最近发现需要向首先提交表单的人发送确认电子邮件,但我不确定如何更改脚本。我基本上需要它来说“亲爱的名字,谢谢你联系我们......”。
请有人帮忙吗?
<?php
//--------------------------Set these paramaters--------------------------
// Subject of email sent to you.
$subject = 'Website Enquiry';
// Your email address. This is where the form information will be sent.
$emailadd = 'myemail@myemail.co.uk';
// Where to redirect after form is processed.
$url = 'thanks.php';
// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';
// --------------------------Do not edit below this line--------------------------
$text = "WEBSITE ENQUIRY:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>
该脚本允许在电子邮件中发送任何表单元素,而无需将其包含在php脚本中。
电子邮件地址收集在html中
<span class="input">
<input type="text" name="Email" id="Email"/>
</span>
和名字......
<span class="input">
<input type="text" name="Name" id="Name" />
</span>
非常感谢
克雷格
答案 0 :(得分:4)
此代码会向提交表单的用户发送确认,但不会检查以确保他们输入了有效的电子邮件地址。在isemail.info有一个方便的脚本,它将为您验证。
将代码插入---Do not edit below this line---
行的正上方。
// Subject of confirmation email.
$conf_subject = 'Your recent enquiry';
// Who should the confirmation email be from?
$conf_sender = 'Organisation Name <no-reply@myemail.co.uk>';
$msg = $_POST['Name'] . ",\n\nThank you for your recent enquiry. A member of our
team will respond to your message as soon as possible.";
mail( $_POST['Email'], $conf_subject, $msg, 'From: ' . $conf_sender );