html mailto不发送电子邮件

时间:2015-12-10 10:34:08

标签: html forms email html-email

我使用简单的表单提交姓名电子邮件和电话号码。

我希望将这些详细信息发送到电子邮件ID,但不发送

有人请帮忙。

<form action="MAILTO:xyz@gmail.com?name=name&email=email" method="post" enctype="text/plain">
<tr>
    <td width="336" height="148" colspan="9">

        <input type="text" name="name" style="width:336; height:40; padding-left:10px" placeholder="Name" required>
        <img src="images/spacer.gif" width="336" height="14" alt="">
        <input type="email" name="email" style="width:336; height:40; padding-left:10px" placeholder="Email Id" required>
        <img src="images/spacer.gif" width="336" height="14" alt="">
        <input type="tel" name="name" style="width:336; height:40; padding-left:10px" placeholder="Contact Number" required>
    </td>
</tr>
<tr>
    <td width="186" height="65" colspan="7">
        <a href="mailto:xyz@gmai.com"><input type="submit" value="Submit" style="width:186; height:65; background-color:black; color:white;"></a></td>

</tr>
</tr>
</form>

3 个答案:

答案 0 :(得分:6)

mailto:不是用于发送电子邮件,而是使用mailto:receiver@abc.com中指定的收件人电子邮件创建邮件。

例如: 如果您使用的是Windows PC,并且将Outlook作为默认电子邮件软件,那么点击<a href="mailto:xyz@gmai.com">将在 <中打开带有 xyz@gmail.com 的Outlook em>到 字段。

如果您想发送电子邮件,可以使用PHP邮件功能来完成。

在表单操作中,而不是mail to function,添加您创建的PHP脚本文件,并遵循此代码结构。

HTML:

<form method="post" action="your_php.php">
    Receiver Email : <input type="text" name="to">
    <input type="submit" value="sendMail"> 
</form>

your_php.php脚本:

<?php
   $to = $_POST['to']; 
   //Getting the 'to' textbox data from the form

   /* If you are using GET method ,then use $_GET[] */

   $subject = "Your Mail Subject" ;
   $message = "Your message to be sent" ;
   $headers = "From: yourmailid@domain.com" ;

   // If you leave the $headers from field empty,then your server mail ID will be displayed 
   and it may be moved to the spam section of the email

   mail($to,$subject,$message,$headers);

   /* Done , Your mail will be sent to the email address you want
?>

这会将邮件发送到所需的电子邮件地址。

P.S。 PHP是一种服务器端脚本语言,所以除非你的网页和php脚本有托管服务器,否则你不能发送邮件。

答案 1 :(得分:1)

the_title()是一个方案前缀,用于将链接标识为电子邮件地址,打开客户端的默认电子邮件应用程序,即您不应将此作为表单的mailto:属性使用

您需要将数据发布到服务器端脚本并使用它来发送数据,例如PHP的mail()函数,假设您已设置服务器。

答案 2 :(得分:1)

如果我理解正确,您希望将所有内容放在一个页面中并从同一页面执行。

您可以使用以下代码从单个页面发送邮件,例如index.php或contact.php

这个和我原来的答案之间的唯一区别是操作留空的位置。

最好使用标题('Location:thank_you.php');而不是在PHP处理程序中使用echo来将用户重定向到另一个页面。

将以下整个代码复制到一个文件中。

<?php 
if(isset($_POST['submit'])){
    $to = "xyz@gmai.com"; // this is your Email address
    $from= $_POST['email']; // this is the sender's Email address
    $name = $_POST['name'];
    $subject = $_POST['contactnumber'];
    $message = $name . " Contact Number:" . "\n\n" . $_POST['contactnumber'];

    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);

    echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    }
?>

<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>

<form action="" method="post">
<tr>
    <td width="336" height="148" colspan="9">

        <input type="text" name="name" style="width:336; height:40; padding-left:10px" placeholder="Name" required>
        <img src="images/spacer.gif" width="336" height="14" alt="">
        <input type="email" name="email" style="width:336; height:40; padding-left:10px" placeholder="Email Id" required>
        <img src="images/spacer.gif" width="336" height="14" alt="">
        <input type="tel" name="contactnumber" style="width:336; height:40; padding-left:10px" placeholder="Contact Number" required>
    </td>
</tr>
<tr>
    <td width="186" height="65" colspan="7">
        <a href="mailto:xyz@gmai.com"><input type="submit" value="Submit" style="width:186; height:65; background-color:black; color:white;"></a></td>

</tr>
</tr>
</form>

</body>

check more in this question

相关问题