EDIT: Apparently I have to pay to register another domain on their site to have email capabilities. Sorry for the wasted time, and thanks for the code fixes.
I don't have any experience with php. I am just starting to figure it out. I am trying to get my form to send the entered information to my email. I set an else tag but that is all that happens. If you see any errors please let me know. I really want this to work. See for yourself: Website The codes are:
HTML:
<form action="post_comment.php" method="post" id="commentform">
<label for="comment_author" class="required">Your Name</label>
<input name="name" id="name" tabindex="1" required="required"><br/><br/>
<label for="email" class="required">Your Email</label>
<input type="email" id="email" name="email" id="email" value="" tabindex="2" required="required"><br/><br/>
<label for="comment" id="comment" class="required">Your Message</label><br/>
<textarea name="comment" rows="10" tabindex="4" required="required"></textarea><br/>
<input id="submit" name="submit" type="submit" value="Submit Comment" />
<input id="send" name="send" type="hidden" value="1" />
</form>
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['comment'];
$from = 'From: '. $email;
$to = 'powersjesse#yahoo.com';
$subject = 'WEBSITE';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['send'] == "1") {
if (mail($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}}
?>
I get Something went wrong, go back and try again! when I'm trying to submit the form.
Updated code.
<form action="post_comment.php" method="post" id="commentform">
rather than method="request"
edited to add
http://www.w3.org/TR/html401/interact/forms.html#h-17.13.1
edited (in response to edited question code...) to add http://php.net/manual/en/function.mail.php
your mail() parameters are in the wrong order; should be $to, $subject, $message [, $additional_headers, etc.]
According to your code:
if ($_REQUEST['submit']) {
if (mail($to, $subject, $body, $from))
{
echo '<p>Your message has been sent!</p>';
}
else
{
echo '<p>Something went wrong, go back and try again!</p>';
}
}
Getting the output of:
Something went wrong, go back and try again!
Means that something went wrong with the mail() function, it returned false , otherwise we would see the Your message has been sent! message.
The problem with the mail() function is that it doesn't show any errors or warning , it just returns false.
How to locate the problem?
Try writing something like:
if(mail("your.working.email#gmail.com" , "A subject for example" , "the content of this email","From: no-reply#yourdomain.com"))
echo "We are good";
else
echo "Something not workin";
If it works , check out the value of any of your posted variables right after declaring them.
echo $name;
echo $email;
echo $message;
Make sure that those variables are not empty and that the $email variable contains a legal and validated email address.
If the basic mail usage didn't work - it's something related to your php settings (php.ini) or a limitation by your server (contact your hosting company).
EDIT1: About your html form , the type attribute of the input fields should be text and not name or email.
Instead of <input type="email"...
Write <input type="text"...
<form action="post_comment.php" method="get" id="commentform">
<label for="comment_author" class="required">Your Name</label>
<input name="name" id="name" tabindex="1" required="required"><br/><br/>
<label for="email" class="required">Your Email</label>
<input type="email" id="email" name="email" id="email" value="" tabindex="2" required="required"><br/><br/>
<label for="comment" id="comment" class="required">Your Message</label><br/>
<textarea name="comment" rows="10" tabindex="4" required="required"></textarea><br/>
<input id="submit" name="submit" type="submit" value="Submit Comment" />
</form>
method must be get/post
Your field "submit" is a HTML button to submit the form and will not be added to the form. Add another input field which is not visible:
<input id="send" name="send" type="hidden" value="1" />
and access the field in PHP with:
if ($_REQUEST['send'] == "1") {
I hope this helps you.
the name of the textarea is comment and you're using it as message in this line,
$message = $_REQUEST['message'];
Needs to be,
$message = $_REQUEST['comment'];
Also, the method of the form submission, needs to be POST like this,
<form action="post_comment.php" method="post" id="commentform">
please change form as follows
<form action="post_comment.php" method="post" id="commentform">
In the form you can use only get/post
Try this
<form action="post_comment.php" method="post" id="commentform">
<label for="comment_author" class="required">Your Name</label>
<input name="name" id="name" tabindex="1" required="required"><br/><br/>
<label for="email" class="required">Your Email</label>
<input type="email" id="email" name="email" id="email" value="" tabindex="2" required="required"><br/><br/>
<label for="comment" id="comment" class="required">Your Message</label><br/>
<textarea name="comment" rows="10" tabindex="4" required="required"></textarea><br/>
<input id="submit" name="submit" type="submit" value="Submit Comment" />
and in your post page..
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: '. $email;
$to = 'powersjesse#yahoo.com';
$subject = 'WEBSITE';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
$headers = "From: $from \r\n";
//$headers .= "Reply-To: $visitor_email \r\n";
mail($to, $subject, $body,$headers);
}
-> Use POST instead of REQUEST
-> comment chaged to message
HTML
<form action="post_comment.php" method="post" id="commentform">
<label for="comment_author" class="required">Your Name</label>
<input name="name" id="name" tabindex="1" required="required"><br/><br/>
<label for="email" class="required">Your Email</label>
<input type="email" id="email" name="email" id="email" value="" tabindex="2" required="required"><br/><br/>
<label for="comment" id="comment" class="required">Your Message</label><br/>
<textarea name="message" rows="10" tabindex="4" required="required"></textarea><br/>
<input id="submit" name="submit" type="submit" value="Submit Comment" />
</form>
PHP
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: '. $email;
$to = 'powersjesse#yahoo.com';
$subject = 'WEBSITE';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
if (mail($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}}
?>
Related
I've built a basic contact form using the following:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$contact = $_POST['contact'];
$message = $_POST['message'];
$from = 'From: Contact';
$to = 'info#mydomain.com';
$subject = 'message';
$body = "From: $name\n E-Mail: $email\n Contact Number: $contact\n Message:\n $message";
?>
<form id="contact-1" method="post">
<label>Name</label>
<input name="name" placeholder="YOUR NAME">
<label>Email</label>
<input name="email" type="email" placeholder="EMAIL ADDRESS">
<label>Contact Number</label>
<input name="contact" type="tel" placeholder="TELEPHONE">
<label>Message</label>
<textarea name="message" placeholder="MESSAGE"></textarea>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
<?php
if ($_POST['submit'] ) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been submitted</p>';
} else {
echo '<p>Something went wrong, please try again!</p>';
}
}
?>
If you leave the name input blank and submit the form, its successful. However, if I add anything the name input. the form doesnt send and the site loads a 'page not found'.
Add type="text" into first input element.
This code appeared to have worked for me, test it out and see if the mail sends properly.
I added the
type="text"
to Name, and added
isset()
around
$_POST['submit']
I enclosed the top potion with
if (isset($_POST['submit']) ) {
To avoid errors before the page is first submitted.
<?php
if (isset($_POST['submit']) ) {
$name = $_POST['name'];
$email = $_POST['email'];
$contact = $_POST['contact'];
$message = $_POST['message'];
$from = 'From: Contact';
$to = 'info#mydomain.com';
$subject = 'message';
$body = "From: $name\n E-Mail: $email\n Contact Number: $contact\n Message:\n $message";
}
?>
<form id="contact-1" method="post">
<label>Name</label>
<input type="text" name="name" placeholder="YOUR NAME">
<label>Email</label>
<input name="email" type="email" placeholder="EMAIL ADDRESS">
<label>Contact Number</label>
<input name="contact" type="tel" placeholder="TELEPHONE">
<label>Message</label>
<textarea name="message" placeholder="MESSAGE"></textarea>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
<?php
if (isset($_POST['submit'])) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been submitted</p>';
} else {
echo '<p>Something went wrong, please try again!</p>';
}
}
?>
I've looked through a lot of pages to find an answer for my problem. But I can't figure out why my form isn't working.
I tried different versions of codes from premade examples but I can't get it to work.
This is my php above my form
<?php
$name = $_POST['name'];
$from = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = 'me#email.com';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $email)) {
echo '<p style="color: #27ae60;">Your message has been sent!</p>';
} else {
echo '<p style="color: #c0392b;">Something went wrong, go back and try again!</p>';
}
}
?>
and this is my form
<form class="contact-form" method="post" action="contact.php">
<label>Name</label>
<input name="name" placeholder="Your Name">
<label>Email</label>
<input name="email" type="email" placeholder="Your Email">
<label>Subject</label>
<input name="subject" placeholder="Your Subject">
<label>Message</label>
<textarea class="contact-form-message" name="message" placeholder="Your Message"></textarea>
<input id="submit" name="submit" type="submit" value="Send">
</form>
I've only changed my email in this example here the rest is the same. I'm testing this live on a modern server with php 5+ support
Basicly everything works fine except that I don't get an email.
I can't find out how to make it work sadly. Any ideas would be cool :/
Edit: GOD DAMNIT IM A TOTAL IDIOT
Gmail Spam filter is strong in this one.
You have not defined $from.
That is why it is not sending mail.
Also, please check SMTP settings for your machine/server.
SMTP ports may not be configured, that is why mail is not sending.
Try this for the form:
<form class="contact-form" method="post" action="contact.php">
<label>Name</label>
<input name="name" type="text" placeholder="Your Name">
<label>Email</label>
<input name="email" type="text" placeholder="Your Email">
<label>Subject</label>
<input name="subject" type="text" placeholder="Your Subject">
<label>Message</label>
<textarea class="contact-form-message" type="text" name="message" placeholder="Your Message"></textarea>
<input id="submit" name="submit" type="submit" value="Send">
Also try following this working format:
<?php
$to = "somebody#example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster#example.com" . "\r\n" .
"CC: somebodyelse#example.com";
mail($to,$subject,$txt,$headers);
?>
You could just replace the value inside the " " with the post function.
Edit ( This will surely work ):
if (isset($_POST['submit'])) {
if (mail ($to, $subject, $body, $email)) {
echo '<p style="color: #27ae60;">Your message has been sent!</p>';
} else {
echo '<p style="color: #c0392b;">Something went wrong, go back and try again!</p>';
}
}
The fourth Parameter for the Mail function is header. Where You can set Mail form and others (http://php.net/manual/en/function.mail.php ). Please set that, and also check the SMTP configuration as "Programming Student" told you.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = 'to#test.com';
$from = 'from#test.com';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if (mail ($to, $subject, $body, $from)) {
echo '<p style="color: #27ae60;">Your message has been sent!</p>';
} else {
echo '<p style="color: #c0392b;">Something went wrong, go back and try again! </p>';
}
?>
You have missed to assign the $from variable
<form class="contact-form" method="post" action="contact.php">
<label>Name</label>
<input name="name" type="text" placeholder="Your Name">
<label>Email</label>
<input name="email" type="text" placeholder="Your Email">
<label>Subject</label>
<input name="subject" type="text" placeholder="Your Subject">
<label>Message</label>
<textarea class="contact-form-message" name="message" placeholder="Your Message"> </textarea>
<input id="submit" name="submit" type="submit" value="Send">
</form>
Make sure the php file name "contact.php"
Now My HTML goes this way -->
<body> Fields with * are mandatory.
<form action="mail.php" method="POST">
<fieldset>
<legend>Contact Information</legend>
<p>Name*</p> <input type="text" name="name">
<p>Email*</p> <input type="text" name="email">
</fieldset>
<br />
<br />
<fieldset>
<legend>Other Information</legend>
<p>Website</p> <input type="text" name="website">
<p>Priority</p>
<select name="priority" size="1">
<option value="Low">Low</option>
<option value="Normal">Normal</option>
<option value="High">High</option>
</select>
<br />
<p>Type</p>
<select name="type" size="1">
<option value="update">Contact Us</option>
<option value="change">Information Change</option>
<option value="addition">Other</option>
</select>
<br />
</fieldset>
<br />
<fieldset>
<legend>Your Message</legend>
<p>Message*</p><textarea name="message" rows="8" cols="29"></textarea><br /><p>
<input type="submit" value="Send" class="but"> <input type="reset" value="Clear" class="but">
</fieldset>
</form>
</body>
and now the main thing that is PHP goes this way ->
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$priority = $_POST['priority'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent=" From: $name \n Email: $email \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message";
$recipient = "youremail#domain.com";
$subject = "Contact Form";
$mailheader = "$name submited the form.";
if (filter_var("$email", FILTER_VALIDATE_EMAIL)) {
if ($email === "" || $message === "" || $name === "") {
echo "ERROR! Email and message and Name are Mandatory. <a href='contact.html' style='text-decoration:none;color:#ff0099;'> Return Back</a>";
}
else {
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
mail($email, "Name of Form Here", "Your Form has been submitted. Your problem will be noticed soon. This is a no reply mail address. Please dont reply back. - WeBoosters India", "Thankyou") or die("Error!");
echo "Thank You!" . " -" . "<a href='index.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
}
}
else {
echo "The email is not valid. Please write a proper email address. - <a href='contact.html' style='text-decoration:none;color:#ff0099;'> Return Back</a>";
}
?>
Hope you like it! Best of luck.
I've got a simple PHP email form. This is going to be used for multiple people, so in order to make it easier for people, I have a hidden input field in my html form that is basically the "mailTo" email address.
How do I get the email to send the email to the address provided in the hidden input field?
Here's my HTML:
<div id="formholder">
<form method="post" action="http://www.artofliz.com/hosting/php/process.php">
<!-- THE CLIENT'S EMAIL TO ADDRESS GOES HERE!!! -->
<input name="to" type="hidden" value="lroberts#platinumstrategies.com" />
<label for="name">Name</label>
<input name="name" placeholder="Full Name" type="text" />
<label for="email">Email</label>
<input name="email" placeholder="youremail#example.com" type="email" />
<label for="phone">Phone</label>
<input name="phone" placeholder="XXX-XXX-XXXX" type="tel" />
<input id="submit" name="submit" type="submit" value="Submit" />
</form>
</div>
Here is my PHP handler:
<?php
$to = $_POST['to'];
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$from = 'From: noreply#platinumstrategies.com';
// $to = 'lroberts#platinumstrategies.com';
$subject = 'Free Guide Download';
$body = "From: $name\n Email: $email\n Phone: $phone";
if ($_POST['submit']) {
/* Anything that goes in here is only performed if the form is submitted */
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
}
?>
http://pastebin.com/cqZP949r - Additionally, I should note that the 'to' that's commented out works fine. It's what I'm trying to do currently that's broken.
Thank you very much for your help.
I am trying to adapt a php script to work with a contact form I am using on my site.
I get the following error when trying to view the page:
Parse error: syntax error, unexpected end of file
If I remove the script all together, I can view my page, so I think the script may be incomplete?
The form and script code is as follows:
<form name="hongkiat" id="hongkiat-form" method="post" action="index.php">
<div id="wrapping" class="clearfix">
<section id="aligned">
<input type="text" name="name" id="name" placeholder="Your name" autocomplete="off" tabindex="1" class="txtinput">
<input type="email" name="email" id="email" placeholder="Your e-mail address" autocomplete="off" tabindex="2" class="txtinput">
<input type="url" name="website" id="website" placeholder="Website URL" autocomplete="off" tabindex="3" class="txtinput">
<input type="tel" name="telephone" id="telephone" placeholder="Phone number?(optional)" tabindex="4" class="txtinput">
<textarea name="message" id="message" placeholder="Enter a cool message..." tabindex="5" class="txtblock"></textarea>
</section>
</div>
<section id="buttons">
<input type="reset" name="reset" id="resetbtn" class="resetbtn" value="Reset">
<input type="submit" name="submit" id="submitbtn" class="submitbtn" tabindex="7" value="Submit this!">
<br style="clear:both;">
</section>
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$telephone = $_POST['telephone'];
$message = $_POST['message'];
$from = 'web address here';
$to = 'email here';
$subject = 'Message from mh web';
$body = "From: $name\n E-Mail: $email\n Website URL: $website\n Telehone: $telephone\n Message:\n $message";
if ($_POST['submit'])
{
if (mail ($to, $subject, $body, $from))
{
echo '<p>Your message has been sent!</p>';
}
else
{
echo '<p>Something went wrong, go back and try again!</p>';
}
?>
</form>
You need another } right before the ?>, to close the if($_POST['submit']){ block. This would be easy to see if the code were properly indented:
if ($_POST['submit'])
{
if (mail ($to, $subject, $body, $from))
{
echo '<p>Your message has been sent!</p>';
}
else
{
echo '<p>Something went wrong, go back and try again!</p>';
}
// oops! missing }
?>
I'd greatly appreciate some help with my PHP contact form. I've followed a number of tutorials to try and get this working and I am still without luck. The code is as follows.
N.B. I am using styling elements defined within the Twitter Bootstrap Framework and the form appears in a modal-style popup (although I can't see why this would affect the form).
Is there anything else I might have to activate/configure on my hosting side apart from having PHP enabled.
FORM CODE:
<form method="POST" action="mail.php">
<fieldset>
<input type="text" name="first_name" placeholder="First Name">
<input type="text" name="last_name" placeholder="Last Name">
<input type="email" name="email" placeholder="Email Address">
<div class="controls controls-row">
<input type="date" name="check_in" placeholder="Check in Date"><span class="help-inline">Check-in</span>
</div>
<div class="controls controls-row">
<input type="date" name="check_out" placeholder="Check out Date"><span class="help-inline">Check-out</span>
</div>
<input type="number" name="rooms" min="1" max="7" placeholder="Number of Rooms">
<input type="number" name="occupants" min="1" max="14" placeholder="Number of Occupants">
<textarea rows="3" name="additional" input class="input-xparge" placeholder="Additional requirements" class="span5"></textarea>
</fieldset>
<div class="modal-footer">
<button type="submit" input type="submit" id="submit" class="btn btn-block btn-large btn-success" value="submit">Submit</button>
</div>
</form>
PHP CODE:
<?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$check_in = $POST['check_in'];
$check_out = $POST['check_out'];
$rooms = $POST['rooms'];
$occupants = $POST['occupants'];
$additional = $_POST['additional'];
$from = "From: $first_name";
$to = "lloyd.rees09#bathspa.ac.uk";
$subject = "New Booking Enquiry";
$body = "First Name: $first_name\n Last Name: $last_name\n Email: $email\n Check In: $check_in\n Check Out: $check_out\n Number of Rooms: $rooms\n Number of Occupants: $occupants\n Additional Information: $additional";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
}
?>
Thank you kindly in advance!
don't you need to add name="submit" to the 'button' tag?
in your php, you are testing 'if ($_POST['submit']) {'
and $_POST['submit'] might not being getting set without name="submit" in that tag