I,m trying to make a form send an e-mail but im getting page not found error.
This is the form itself
<form action="sendmail.php" method="post">
<div>
<div class="row half">
<div class="6u">
<input type="text" class="text" name="name" placeholder="Name" />
</div>
<div class="6u">
<input type="text" class="text" name="email" placeholder="Email" />
</div>
</div>
<div class="row half">
<div class="12u">
<input type="text" class="text" name="subject" placeholder="Subject" />
</div>
</div>
<div class="row half">
<div class="12u">
<textarea name="message" placeholder="Message"></textarea>
</div>
</div>
<div class="row">
<div class="12u">
<input type="submit" class="button" value="Send Message" />
</div>
</div>
</div>
</form>
And this is the PHP file named sendmail.php
<?php
$to = "info#aroundgalaxy.pt";
$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
//$site = $_REQUEST['site'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$headers = "noreply#aroundgalaxy.pt";
$body = "From: $name \n\n Email: $email \n\n Message: $message";
$sent = mail($to, $subject, $body, $headers) ;
if($sent)
{echo "<script language=javascript>window.location = 'LINK BACK TO CONTACT PAGE';</script>";}
else
{echo "<script language=javascript>window.location = 'LINK BACK TO CONTACT PAGE';</script>";}
?>
Am i missing something?
Thanks
The code should work. I dont think there is a problem with the code. Just make sure both the form page & sendmail.php are on the same directory
Related
How to add receiver address to my contact form. I tried and searched a lot but i cant solve the issue by myself. help! Thx!!!
<article id="contact">
<h2 class="major">Contact</h2>
<form name="contactform" method="post" action="index.html">
<div class="fields">
<div class="field half">
<label for="name">Name</label>
<input type="text" name="name" id="name" />
</div>
<div class="field half">
<label for="email">Email</label>
<input type="text" name="email" id="email" />
</div>
<div class="field half">
<label for="email">Telefon</label>
<input type="text" name="telefon" id="email" />
</div>
<div class="field half">
<label for="email">Subject</label>
<input type="text" name="subject" id="email" />
</div>
<div class="field">
<label for="message">Message</label>
<textarea name="message" id="message" rows="4"></textarea>
</div>
</div>
<ul class="actions">
<li><input type="submit" value="Send Message" class="primary"/></li>
<li><input type="reset" value="Reset" /></li>
</ul>
</form>
</article>
Receiver mailId add at php side, you can pass receiver mailId as "to" filed in php mail function.
mail($to,$subject,$txt,$headers);
If you implement your sending mail in other way then send your php code
You need to update your action in form element
<form name="contactform" method="post" action="some_php_page.php">
and in some_php_page.php you need to add bellow code.
if(isset($_Post['name']){
$to = "Receiver Email Id ";
$subject = "Your Subject";
$name = trim($_POST['name']);
$email = $_Post['email'];
$telefon = $_Post['telefon'];
$subject = $_Post['subject'];
$message = $_Post['message'];
$body = "Name: ".$name.'\n';
$body .= "Email: ".$email.'\n';
$body .= "Subject: ".$subject.'\n';
$body .= "Message: ".$message.'\n';
mail($to,$subject,$body);
}
Hope this will help you...
I need help, i'm trying to set up a contact form, I have the code and think I have it set up correctly with HTML and PHP. When I submit to test it on my testsite it send an email through but the email is blank.
Thanks in advance if you can help me please.
HTML:
<div class="col-md-6 contact-right">
<form name="contactform" action="mailer.php" method="post" role="form" enctype="text/plain">
<div class="styled-input agile-styled-input-top">
<input type="text" class="form-control" name="name" placeholder="Your Name">
<label for="name">Name</label>
<span></span>
</div>
<div class="styled-input">
<input type="text" class="form-control" name="email" placeholder="Your Email">
<label for="email">Email</label>
<span></span>
</div>
<div class="styled-input">
<input type="text" class="form-control" name="subject" placeholder="Subject">
<label for="subject">Subject</label>
<span></span>
</div>
<div class="styled-input">
<textarea class="form-control" rows="4" name="message" placeholder="Your message..."></textarea>
<label for="message">Message</label>
<span></span>
</div>
<input type="submit" value="Submit" name="submit">
</form>
</div>
<div class="clearfix"> </div>
</div>
</div>
</div>
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "laura#ironcladdesign.co.uk";
$subject = "Enquiry from CK9C Website";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! We will be in touch very soon";
?>
The problem is here:
<form name="contactform" action="mailer.php" method="post" role="form" enctype="text/plain">
You are encoding as "text/plain". Replace with "application/x-www-form-urlencoded" which is the default or don't include enctype and that will be the default.
you can try it in place of $_POST
if ((!is_array($_POST)) || (count($_POST) < 1)) {
$_POST = json_decode(file_get_contents('php://input'), true);
}
I have a problem with my contact form. When testing it I receive an email with no content. Just empty input titles "from: (empty) Message: (empty)".
PHP CODE
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "mymail#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
HTML CODE FORM
<form method="post" action="mail.php">
<div class="row 50%">
<div class="6u">
<input name="name" placeholder="Name" type="text" class="text" />
</div>
<div class="6u">
<input name="email" placeholder="Email" type="text" class="text" />
</div>
</div>
<div class="row 50%">
<div class="12u">
<textarea name="message" placeholder="Message"></textarea>
</div>
</div>
<div class="row 50%">
<div class="12u">
Send Message
</div>
</div>
</form>
You are not passing a form because you simply link to mail.php with your <a>. The way you are doing it, $_POST will always be empty as your form isn't submitted.
Please change this line
Send Message
to
<input type="submit" class="button alt" value="Send Message"/>
I've made this php which will send me messages right to my inbox. Even though the script works fine on desktops and laptops I can't use on phones. Why is this happening? Am I doing something wrong? ( I tried the form on iPhone 6+ and Samsung Alpha)
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "info#mydomain.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header('Location: message-sent.html#contact'); exit();
?>
And this is the html code for the phone.
<form method="post" action="mail.php">
<div class="row 50%">
<div class="6u">
<input name="name" placeholder="Name" type="text" class="text" />
</div>
<div class="6u">
<input name="email" placeholder="Email" type="text" class="text" />
</div>
</div>
<div class="row 50%">
<div class="12u">
<textarea name="message" placeholder="Message"></textarea>
</div>
</div>
<div class="row 50%">
<div class="12u">
<input type="submit" class="button alt" value="Send Message"/>
</div>
</div>
</form>
Thank you all in advance for your help.
I'm currently working on a HTML form that uses PHP to send a message to email. I'm testing in MAMP and am unable to get a response after clicking "send message". Any advice would be much appreciated.
HTML
<form action="mail.php" method="POST">
<div class="row half">
<div class="6u">
<input type="text" class="text" name="name" placeholder="Name" />
</div>
<div class="6u">
<input type="text" class="text" name="email" placeholder="Email" />
</div>
</div>
<div class="row half">
<div class="12u">
<textarea name="message" placeholder="Message" rows="6" cols="25"></textarea>
<br />
</div>
</div>
<div class="row">
<div class="12u">
<ul class="actions">
<li class="button form" input type="submit" value="Submit">Send Message</li>
</ul>
</div>
</div>
</form>
PHP
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$to = 'my#email.com';
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
$send_message=mail($to, $subject, $formcontent, $mailheader);
if($send_message){
echo "thank you"
} else {
echo "error";
}
?>
Thanks
found some errors in ur code
correct this:
<li class="button form" input type="submit" value="Submit">Send Message</li>
to
<li class="button form"> <input type="submit" value="Submit">Send Message</li>
correct this:
echo "thank you"
to echo "thank you";
Are you checking this in your local server? php mail() function may probably not work in local servers.Check it in some online servers(after correcting the bugs mentioned by #Ashish ).
HTML
<form action="mail.php" method="POST">
<div class="row half">
<div class="6u">
<input type="text" class="text" name="name" placeholder="Name" />
</div>
<div class="6u">
<input type="text" class="text" name="email" placeholder="Email" />
</div>
</div>
<div class="row half">
<div class="12u">
<textarea name="message" placeholder="Message" rows="6" cols="25"></textarea>
<br />
</div>
</div>
<div class="row">
<div class="12u">
<ul class="actions">
<li class="button form"> <input type="submit" value="Submit" name="sendmessage"/>Send Message</li> // Use name attribute
</ul>
</div>
</div>
*Use Name Attribute *
PHP
<?php
if($_POST['sendmessage']!="")
{
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$to = 'my#email.com';
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
$send_message=mail($to, $subject, $formcontent, $mailheader);
if($send_message){
echo "thank you";
} else {
echo "error"; }
}
?>
Try this code.