-1

我目前在我的网络服务器上即将推出的页面上有一个表单,我需要捕获输入的电子邮件地址并将其发送到我的电子邮件地址,例如example@hotmail.com

使用 PHP 完成此任务的最佳方法是什么?

<form method="post">

<input class="emailsubscribe mobile clearfix" type="text" name="mail" 
placeholder="Enter your email" onFocus="if(!this._haschanged)
{this.value=''};this._haschanged=true;"/>

<input class="emailsubscribe desktop clearfix" type="text" name="mail" 
placeholder="Enter your email to stay up to date" onFocus="if(!this._haschanged)
{this.value=''};this._haschanged=true;"/>

<input class="emailsubmit clearfix" type="submit" name="submit"/>

</form>

提前致谢!

4

3 回答 3

2

HTML

<form method="post" action="send.php">
    Enter your e-mail: <input type="text" name="email" />
    <input type="submit" name="submit" value="Submit" />
</form>

PHP(发送.php):

if(!isset($_POST['submit']) || !isset($_POST['email'])) die();
$email = $_POST['email'];
mail('youremail@gmail.com', 'Subject', 'Entered e-mail: '.$email);

您应该添加某种保护,例如验证码,以防止垃圾邮件。

于 2012-07-08T12:18:12.977 回答
0

使用PHPMailer类发送电子邮件或只是一个php 邮件功能

于 2012-07-08T12:16:37.927 回答
0

您的表单中有 2 个具有相同名称的输入。

if (isset($_POST['submit'])) {
    $email = $_POST['email']; // Check first if is a valid email address with either filter_var or a regex. 
    $recipient = "therecipient@email.com"; 
    $mail_body = "Any message you wan to include here"; 
    $subject = "From online Form"; 
    $header = "From: Online Form: <" . $email . ">\r\n"; 

    mail($recipient, $subject, $mail_body, $header);
}
于 2012-07-08T12:26:01.320 回答