gpt4 book ai didi

php - 使用 php 发送确认电子邮件

转载 作者:行者123 更新时间:2023-12-02 15:41:04 25 4
gpt4 key购买 nike

我正在使用下面的脚本将包含已提交字段的电子邮件返回到我的电子邮件地址。

我最近发现需要向最初提交表单的人发送一封确认电子邮件,但不确定如何更改脚本。我基本上需要它说类似“亲爱的 $name,感谢您联系我们......”。

有人可以帮忙吗?

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

非常感谢

克雷格

最佳答案

此代码将向提交表单的用户发送确认,但不会检查以确保他们输入了有效的电子邮件地址。 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 );

关于php - 使用 php 发送确认电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6142433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com