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">
<input type="submit" value="Submit" style="width:186; height:65; background-color:black; color:white;"></td>
</tr>
</tr>
</form>
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.
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.
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">
<input type="submit" value="Submit" style="width:186; height:65; background-color:black; color:white;"></td>
</tr>
</tr>
</form>
</body>
check more in this question
Related
So I have made myself a website. Since it has plans for being used I need someones help :)
I need users to fill in a few boxes and then send it to my email at thisismyemail#provider.com.
Since I am a little new I dont now how to do it.
The form: http://imgur.com/U5Q3jrE
This is my code:
<form action="../index.html" method="post" class="message">
<input type="text" value="Naam" onFocus="this.select();" onMouseOut="javascript:return false;"/>
<input type="text" value="E-mail" onFocus="this.select();" onMouseOut="javascript:return false;"/>
<input type="text" value="Onderwerp" onFocus="this.select();" onMouseOut="javascript:return false;"/>
<textarea></textarea>
<input type="submit" value="Send"/>
</form>
Now what I need is that it doesnt bring me to the index page but show a message with someone like: "Your message has been send" and that it sends it to my email, because at the moment it doesnt send it to anything.
Once more I am pretty new so please forgive my noobness :P
Thanks everyone,
Waylon194
Ok here's a php html code that can be used to email, that you can start with.
User inputs must always be sanitized accordingly. This code is just for demonstration.
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "someone#example.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$comment = $_REQUEST['comment'];
//send email
mail($admin_email, "$subject", $comment, "From:" . $email);
//Email response
echo "Thank you for contacting us!";
}
//if "email" variable is not filled out, display the form
else {
?>
<form method="post">
Email: <input name="email" type="text" /><br />
Subject: <input name="subject" type="text" /><br />
Message:<br />
<textarea name="comment" rows="15" cols="40"></textarea><br />
<input type="submit" value="Submit" />
</form>
<?php
}
?>
For my website I'm working on a contact form, which works. But I want the submit button to be like other buttons on my site, meaning I want it to be styled like the code below.
However, I can't get it to submit via a "href" code.
I've tried applying answers on similar questions but haven't had any luck.
Any help would be greatly appreciated!
THE STYLE FOR THE SUBMIT BUTTON I WANT TO USE:
<div class="section-buttons">
<p class="button layer" data-depth="0.10" ><a href = "I WANT THIS TO SUBMIT THE FORM"
class="y1 knop roll swing"><span class="g1">SUBMIT</span><span class="g2">SUBMIT</span>
</a></p>
</div>
THE FORM CODE:
<form action="form.php" method="post" enctype="multipart/form-data">
<label></label>
<input name="name" required placeholder="Name">
<label></label>
<input name="email" type="email" required placeholder="E-mail">
<label></label>
<textarea name="message" cols="20" rows="5" required placeholder="Message">
</textarea>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
EDIT:
Thanks a lot for the quick replies. Really appreciated.
Celt, your solution definitely brings me close to the solution.
It does indeed bring me to the form.php but it doesn't seem to submit the actual data to an email address.
Could it be that my PHP file (forms.php) does something wrong with the new code? I'm guessing the last part "if ($_POST['submit'])" doesn't quite work with this new approach? Any help?
Sorry for the noobness.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: website.com';
$to = 'email#email.com';
$subject = 'Email Inquiry';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
?>
<?php
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Thank you for your email!</p>';
} else {
echo '<p>Oops! An error occurred. Try sending your message
again.</p>';
}
}
?>
This should work for you:
I am using Magento, and I have a form.html that asks for customer data. When the customer is logged in, I want to prepopulate the relevant fields with known data.
I have used the following constructs, but none work.
The listing begins with the (commented out) line that just asks for filling in, then my two modifications, the first one commented out. Both are not working. What's wrong?
<!--<td valign="top"><input maxlength="30" name="name" size="20" type="text"></td>-->
<!--<td valign="top"><echo Mage::getSingleton('customer/session')->getCustomer()->getName();></td>-->
<td valign="top">
<input type="text" name="name" value="<?php echo Mage::app()->getRequest()->getPost("name");?>" />
</td>
Your first modification (second line commented out) won't work because you haven't wrapped the PHP in its tags.
Try writing a statement to check if the customer is logged in.
<?php
if (Mage::getSingleton('customer/session')->isLoggedIn()) :
//Write out the customer's full name
echo Mage::getSingleton('customer/session')->getCustomer()->getName();
else :
echo 'Customer not logged in';
endif;
?>
If there is still no value being returned it might be because you haven't got the customer's session ID.
<?php
$customer = new Varien_Object();
if (Mage::getSingleton('customer/session')->isLoggedIn()){
$customer = Mage::getSingleton('customer/session')->getCustomer();
}
?>
<td valign="top">
<input type="text" name="name" value="<?php echo $customer->getData('name') ?>" />
</td>
I found this example on w3schools and change email to my email, but when I click Send nothing happens. Where is the problem?
<h3>Send e-mail to someone#example.com:</h3>
<form action="MAILTO:someone#example.com" method="post" enctype="text/plain">
Name:<br>
<input type="text" name="name" value="your name"><br>
E-mail:<br>
<input type="text" name="mail" value="your email"><br>
Comment:<br>
<input type="text" name="comment" value="your comment" size="50"><br><br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
Don't do this. It is unreliable as it depends on the mail client the user has installed and you can not test for that.
instead you should either post the form data to a php script that uses the
php mail() function - which is easy to learn
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = $_POST['comment'];
$headers = 'From:'. $_POST['email']. "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
or use a cgi script like
http://www.response-o-matic.com/
You aren't really sending the email when you use the mailto:someone#example.org All you're doing is telling the browser that it should handle what follows as an email address and so, the browser will open the default mail client.
The only way to send an email programmatically, which I think is what you are trying to do, is to use a server side script. Something like PHP or ASP.NET to just give two examples.
I need some help, I'm building a website for a good friend and I need some help with the contact form. I found the code online but it's not working correctly. It sends the e-mail but not all the forms correctly, and doesn't send the picture. Also, when I send the form, it should link to the page contactus.html, but the link doesn't seem to work either. Can anyone help correct this code, this would help SO much. Thank you so, so much.
Here is the HTML for the contact form:
<div id="stylized" class="myform">
<form id="form" id="form" action="mail.php" method="POST">
<label>Name
<span class="small">Add your name</span>
</label>
<input type="text" name="name">
<label>Address
<span class="small">Add your home address</span>
</label>
<input type="text" name="address">
<label>Phone
<span class="small">Add a Phone Number</span>
</label>
<input type="text" name="phone">
<label>E-mail
<span class="small">Enter a valid E-mail</span>
</label>
<input type="text" name="email">
<label>Timeline
<span class="small">Range for your project</span>
</label>
<input type="text" name="timeline">
<label>Photo
<span class="small">Upload current picture</span>
</label>
<input type="file" name="photo">
<label>Description
<span class="small">Type Your Project Description</span>
</label>
<textarea name="message" rows="6" cols="25"></textarea>
<button type="submit" value="Send" style="margin-top:15px;">Submit</button>
<div class="spacer"></div>
</form>
</div>
And here is mail.php, which is supposed to help make the form work. I think here is where the problem is:
<?php $name = $_POST['name'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$timeline = $_POST['timeline'];
$description = $_POST['description'];
$formcontent="From: $name \n Message: $message";
$recipient = "blanger#hawaii.edu";
$subject = "New Project Request from 2DadsDB.com";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='contactus.html'>Go Back</a>";
?>
As Blender pointed out the code is very insecure. It's easy for malicious content to be inserted. Also there's no reference in the mail.php to "photo"
$fileImage = $_POST['photo'];
You'll need to use a script to upload and store the photo I believe. It's best too look at a tutorial or complete source instead of building from scratch.
The mail() function is good for only message sending.
To send an image First you need to upload your photo to the server To upload an image.
To send an image using mail() first attach your photo from server to mail() PHP e-mail attachment script
And use $name = mysql_real_escape_string(strip_tags($_POST['name']));
for each post like name,e-mail etc., for security purpose.
You should sanitize your imputs.Use mysql_real_escape_string or stripslashes function on each of the $_POST.
$user = mysql_real_escape_string($_POST['user']);