3

I am using a simple form to submit name email and phone number.

I want these details to be sent to an email id, but it is not sending

Someone please help.

<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>
Abdulla
  • 441
  • 1
  • 9
  • 21

3 Answers3

6

The mailto: is not for sending emails, instead it will create a mail with the receiver email specified in the mailto:receiver@abc.com.

For e.g : If you are having a windows PC and if you have Outlook as your default email software ,then clicking on the <a href="mailto:xyz@gmai.com"> will open up outlook with xyz@gmail.com in the to field.

If you want to send emails you can use PHP mail function to do it.

In the form action instead of mail to function add a PHP script file you have created and follow this code structure.

HTML :

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

your_php.php script :

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

This will send the mail to the required email address.

P.S. PHP is a server side scripting language ,So you cannot send the mail unless you have a hosting server for your webpage and php script.

It Assistors
  • 998
  • 2
  • 14
  • 29
1

mailto: is a scheme prefix to identify a link as an email address, opening the default email application for the client, i.e. you shouldn't use this as an action attribute for a form.

You need to POST the data to a server-side script and use that to send the data, such as PHP's mail() function, assuming you have the server set up to do so.

Benjy1996
  • 159
  • 7
1

If I understand correctly, you wish to have everything in one page and execute it from the same page.

You can use the following code to send mail from a single page, for example index.php or contact.php

The only difference between this one and my original answer is the where the action has been left blank.

It is better to use header('Location: thank_you.php'); instead of echo in the PHP handler to redirect the user to another page afterwards.

Copy the entire code below into one file.

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

Community
  • 1
  • 1