2011-05-26 105 views
0

我正在使用以下腳本將提交的字段返回給我的電子郵件地址。使用php發送確認郵件

我最近發現需要發送一封確認郵件給誰曾經提交過表格,但我不確定如何更改腳本。我基本上需要它說「親愛的$的名字,感謝您與我們聯繫......」。

請問有人可以幫忙嗎?

<?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 = '[email protected]'; 

// 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

你的腳本簡單地發送表單發回給用戶,除非你有沒有包括它的表單數據發送到您 – 2011-05-26 17:27:45

+0

這是正確的部分 - 我不偉大的PHP的 - 所以我無法解決剩下的問題。如果可能,我正在尋求幫助。 – 2011-05-26 18:08:27

+0

僅供參考:該腳本的大部分內容僅用於驗證和格式化輸入。實際的電子郵件發送到底部。您應該熟悉PHP郵件功能:http://php.net/manual/en/function.mail.php – 2011-05-26 18:29:49

回答

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 <[email protected]>'; 

$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);