简体   繁体   English

通过表单输入将电子邮件发送到地址

[英]Send email to address from form input

I have a pretty standard contact form with inputs for name, email address and phone number. 我有一个非常标准的联系表,其中包含姓名,电子邮件地址和电话号码的输入。 As well as sending the email to the specified email address as per a standard form, 按照标准格式将电子邮件发送到指定的电子邮件地址,

$to      = 'diysoakwells@hotmail.com';

I would also like to send the email to the user using the address from the email address input from the form. 我还想使用从表单输入的电子邮件地址中的地址将电子邮件发送给用户。 I was thinking using the post variable from the email input like this would work: 我正在考虑使用来自电子邮件输入的post变量,如下所示:

$to      = 'diysoakwells@hotmail.com', $email;

but no luck. 但没有运气。 Can someone point me in the right directiona and are there any security risks in using this approach? 有人可以指出我正确的方向吗?使用此方法是否存在安全隐患? I ultimately aim to provide the user with a checkbox that if checked sends a copy of the email to themselves. 我的最终目的是为用户提供一个复选框,如果选中该复选框,则会向自己发送电子邮件的副本。

Here is a link to my form 这是我表格的链接

http://www.diysoakwells.com.au/cart.php http://www.diysoakwells.com.au/cart.php

Thankyou in advance : ) 先感谢您 : )

<?php
include_once("wsp_captcha.php");

if(WSP_CheckImageCode() != "OK") {
header('location:/form-rejected.php');
die();
}
$to      = 'diysoakwells@hotmail.com';
$subject = 'Order Inquiry';
$jcitems = " <p><b>ORDER:</b></p><p> " . $_POST['jcitems']."<p/>" . "<p><b>Total:</b> $" . $_POST['jctotal']."</p>";
$time = date ("h:i A"); 
$date = date ("l, F jS, Y");
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= 'From: inquiry@diysoakwells.com' . "\r\n" .
'Reply-To: noreply@diysoakwells.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$name = $_POST['name'];
$phone = $_POST['phone'];
$emaile = $_POST['emaile'];
$textbox = $_POST['textbox'];
$text = "<html><body><p><b>Message:</b>\n$textbox</p><p>This form was submitted on Your Web Site on \n $date at\n $time</p><p><b>Customers Email Address:</b> $emaile</p><p><b>Customers Name:</b> $name </p><p><b>Customers Phone Number:</b> $phone </p></html>    </body>";
$body = $text . $jcitems;
mail($to, $subject, $body, $headers);
Header('Location: ../form-accepted.php');
?>

What your doing is not what you want to do. 您所做的不是您想做的。 Concatenating two strings in PHP is done with the . 在PHP中连接两个字符串是通过来完成的。 not the , so the correct syntax is: 不是,因此正确的语法是:

$to      = 'diysoakwells@hotmail.com'.", ".$emaile;

or simply 或简单地

$to      = "diysoakwells@hotmail.com, $emaile";

That's assuming that the code in charge of sending the email uses php's mail() function, which allows multiple emails in the $to argument. 假设负责发送电子邮件的代码使用php的mail()函数,该函数允许$ to参数中包含多封电子邮件。 If that doesn't work, I can't be of more use without seeing the actual code. 如果这不起作用,那么在没有看到实际代码的情况下我将无用处。

The 'to' field on emails accepts a string, with the email address comma-separated. 电子邮件的“收件人”字段接受字符串,电子邮件地址用逗号分隔。

$to = 'diysoakwell@hotmail.com, ' . $emaile;

should do the trick. 应该可以。

You should check the email address that they provide is formatted as an email address, and it would be a good idea to have a CAPTCHA to prevent automated bots from using your form as a spamming tool. 您应该检查他们提供的电子邮件地址的格式设置为电子邮件地址,最好使用CAPTCHA来防止自动程序将您的表单用作垃圾邮件发送工具。

If you use php mail() function you can send copy by specifying additional headers like that: 如果您使用php mail()函数 ,则可以通过指定其他标头来发送副本,如下所示:

$headers = 'Cc: '.$emaile;
mail($to, $subject, $message, $headers);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM