I've been looking around everywhere and cannot seem to find how to make this work - it is simply not sending an email to my address. Here is my HTML form:
<form id="contactMe" name="contact" method="post" novalidate="novalidate">
<fieldset>
<label for="name" id="name">Name<span class="required">*</span></label>
<input type="text" name="name" id="name" size="30" value="" required="">
<label for="email" id="email">Email<span class="required">*</span></label>
<input type="text" name="email" id="email" size="30" value="" required="">
<label for="phone" id="phone">Phone</label>
<input type="text" name="phone" id="phone" size="30" value="">
<label for="Message" id="message">Message<span class="required">*</span></label>
<textarea name="message" id="message" required=""></textarea>
<label for="Answer" id="answer">Name the house pet that says “<i>woof</i>“<span class="required">*</span></label>
<input type="text" name="answer" value="" required=""></br>
<input id="submit" type="submit" name="submit" value="Send">
</fieldset>
<div id="success">
<span class="green textcenter">
<p>Your message was sent successfully! I will be in touch as soon as I can.</p>
</span>
</div> <!-- closes success div -->
<div id="error">
<span><p>Something went wrong, try refreshing and submitting the form again.</p></span>
</div> <!--close error div-->
</form>
and here is my PHP saved as mailer.php:
<?php
$to = "someone#gmail.com";
$from = $_REQUEST['email'];
$name = $_REQUEST['name'];
$headers = "From: $from";
$subject = "You have a message from your.";
$fields = array();
$fields{"name"} = "name";
$fields{"email"} = "email";
$fields{"phone"} = "phone";
$fields{"message"} = "message";
$body = "Here is what was sent:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
mail("maytee.kneitz#gmail.com",$subject,$message,"From: $from\n");
echo 'Mail sent';
?>
This is my first shot at working on a mailer / contact form, so sorry if it's a blatant problem. I just can't seem to find it. Any guidance would be appreciated.
I do have validation in my scripts (not posted here).
You don't have a form action defined. Try this:
<form id="contactMe" name="contact" method="post" action="mailer.php" novalidate="novalidate">
By default, the form will be submitted to its current location unless otherwise specified. In your case, point it to wherever your mail script is located
Related
so I am trying to make a link to contact form but it seems to be crashing and I do not know why is this happening. I double checked the link and variable name, but seems like error 405 happens without stopping every time I click.
This is my html part
<h3>Contact Form</h3>
<div class="containerofcontact" style="text-align: left !important;">
<form method="POST" action="contactform.php">
<label for="name">Name</label>
<input type="text" id="Name" name="Name" placeholder="Your name..">
<label for="email">Email</label>
<input type="text" id="Email" name="Email" placeholder="Your Email">
<label for="subject">Subject</label>
<textarea id="Subject" name="Subject" placeholder="Place Detail of Concern" style="height:200px"></textarea>
<input type="submit" value="Send">
</form>
</div>
This is php part
<?php
$name = $_POST['Name'];
$email = $_POST['Email'];
$text = $_POST['Subject'];
$mailTo = "blankforshare";
$headers = "From: ".$email;
$txt = "You have received an e-mail from ".$name."\n\n".$text;
mail($mailTo, $headers, $txt) or die("Error!");
header("Location: index.html");
?>
Thank you for the help.
I am using Ampps on Mac and trying to send an email using php from a contact form however I do not receive the mail and when the form is submitted it redirects me to the file page resulting in a blank display
my form :
<form action="email.php" method="post">
<div class="col-md-6 w3_agileits_contact_left">
<span class="input input--akira">
<input class="input__field input__field--akira" type="text" id="input-22" name="Name" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-22">
<span class="input__label-content input__label-content--akira">Your name</span>
</label>
</span>
<span class="input input--akira">
<input class="input__field input__field--akira" type="email" id="input-23" name="Email" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-23">
<span class="input__label-content input__label-content--akira">Your email</span>
</label>
</span>
<span class="input input--akira">
<input class="input__field input__field--akira" type="text" id="input-24" name="Subject" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-24">
<span class="input__label-content input__label-content--akira">Your subject</span>
</label>
</span>
</div>
<div class="col-md-6 w3_agileits_contact_right">
<div class="w3_agileits_contact_right1">
<textarea name="Message" id="Message" placeholder="Your comment here..." required=""></textarea>
</div>
<div class="w3_agileits_contact_right2">
<input type="submit" value="Send">
</div>
<div class="clearfix"> </div>
</div>
<div class="clearfix"> </div>
</form>
my File :
$email = $_POST['Email'];
$name = $_POST['Name'];
$to = "lucvanrooyen#gmail.com";
$subject = $_POST['Subject'];
$userMessage =$_POST['Message'];
$headers = "From: $email\n";
$message = "$name has sent you the following message.\n
Message: $userMessage";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: lucvanrooyen#gmail.com\n";
$usermessage = "Thank you for your enquiry we will be in touch.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
The code you have shown is not enough to debug your problem.
If you are using the mail method which is built into the standard library, read this answer to find out a few troubleshooting steps you could follow.
If you are and are still finding it difficult to use, then you could consider using one of the PHP emailing solutions like -
PHPMailer
SwiftMailer
Please check your form tag. there is no opening tag for form
<form action="email.php" method="post">
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I haven't written code in years, so I am going off old code from a project that is over 5 years old, so I am not surprised that it doesn't work; I would like some pointers on how to make it work, please.
Here is what I have in my HTML email form --
<form action="fydcontact.php" method="post">
<div class="form-group">
<!--<label for="contact_name">Name:</label>-->
<input type="text" id="contact_name" class="form-control" placeholder="Name" />
</div>
<div class="form-group">
<!--<label for="contact_email">Email:</label>-->
<input type="text" id="contact_email" class="form-control" placeholder="Email Address" />
</div>
<div class="form-group">
<!--<label for="contact_message">Message:</label>-->
<textarea id="contact_message" class="form-control" rows="9" placeholder="Write a message"></textarea>
</div>
<button type="submit" class="btn btn-primary">Send</button>
</form>
and here is what my PHP looks like --
<?php
if(isset($_POST['send'])) {
// Prepare the email
$to = ''foryourdayformals#gmail.com ';
$name = $_POST['contact_name'];
$mail_from = $_POST['contact_email'];
$subject = 'Message sent from website';
$message = $_POST['contact_message'];
$header = "From: $name <$mail_from>";
// Send it
$sent = mail($to, $subject, $message, $header);
if($sent) {
echo 'Your message has been sent successfully! Return to For Your Day, LLC Website';
} else {
echo 'Sorry, your message could not send. Please use direct email link on Contact Us page (below the map). Return to For Your Day, LLC Website';
}
}
?>
Any help is GREATLY appreciated! Thanks!
update
$to = ''foryourdayformals#gmail.com ';
to
$to = 'foryourdayformals#gmail.com';
and need to add name attribute for form . This update your form
<form action="fydcontact.php" method="post">
<div class="form-group">
<!--<label for="contact_name">Name:</label>-->
<input type="text" id="contact_name" name="contact_name" class="form-control" placeholder="Name" />
</div>
<div class="form-group">
<!--<label for="contact_email">Email:</label>-->
<input type="text" id="contact_email" name="contact_email" class="form-control" placeholder="Email Address" />
</div>
<div class="form-group">
<!--<label for="contact_message">Message:</label>-->
<textarea id="contact_message" name="contact_message" class="form-control" rows="9" placeholder="Write a message"></textarea>
</div>
<button type="submit" class="btn btn-primary" name ="send">Send</button>
</form>
I am working on my version 2 of my portfolio site, I had a working mailer I created with a guide about a year ago, transferred it, and can't get my page to display now.
Here is the code I am using:
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$subject = $_REQUEST["My_Portfolio_Website"] ;
$message = $_REQUEST['message'] . "\nName: " . $name . "\nEmail: ".$email; "\n \nMessage: ".$message;
echo "<h1>Thank you for contacting me. I will get back to you ASAP!</h1>";
}else{
//if "email" is not filled out, display the form
echo <form method="post" action="contact.php" class="connect">
<div>
<input id="name" name="name" type="text" required>
<label for="name">Your Name</label>
</div>
<div>
<input id="email" name="email" type="text" required>
<label for="email">Your Email</label>
</div>
<div>
<textarea id="message" name="message" required></textarea>
<label for="message">Your Message</label>
</div>
<div class="metro">
<div class="metro-button" type="submit">Click me</div>
</div>
</form>
}
?>
I ran it through a PHP syntax checker and it did not pull anything out, does anyone have any ideas?
For reference: Here is the original code I used on Version 1. I formatted it so it would display the email a little more cleaner, which probably royally screwed it up.
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$subject = $_REQUEST["My Portfolio Website"] ;
$message = $_REQUEST['message'].", Name: ".$name.", ".$phone.", Email: ".$email;
mail("TylerJStelmach#gmail.com", $subject, $message, "From:" . $email);
echo "<h1>Thank you for contacting me. I will get back to you ASAP!</h1>";
}else{
//if "email" is not filled out, display the form
echo "<form method='post' action='index.php'>
<input type='text' input name='name' id='name' class='contacttext' placeholder=' Your Name' required>
<input type='text' input name='email' id='email' class='contacttext' placeholder=' Your Email Address' required>
<textarea input type='text' name='message' id='message' class='contacttext' placeholder=' Your Message' cols='55' rows='5' required></textarea>
<input type='submit' id='submit' class='submitcontacttext' value='Send Message'>
</form>";
}
?>
There are some syntax errors.
Also, your snipplet does not contain code to send mail.
Corrected code is as following:
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$subject = $_REQUEST["My_Portfolio_Website"] ;
$message = $_REQUEST['message'] . "\nName: " . $name . "\nEmail: ".$email; "\n \nMessage: ".$message;
echo "<h1>Thank you for contacting me. I will get back to you ASAP!</h1>";
}else{
//if "email" is not filled out, display the form
echo '<form method="post" action="contact.php" class="connect">
<div>
<input id="name" name="name" type="text" required>
<label for="name">Your Name</label>
</div>
<div>
<input id="email" name="email" type="text" required>
<label for="email">Your Email</label>
</div>
<div>
<textarea id="message" name="message" required></textarea>
<label for="message">Your Message</label>
</div>
<div class="metro">
<div class="metro-button" type="submit">Click me</div>
</div>
</form>';
}
?>
as all are saying where is the line to send mail but as i have seen your site there is no sign of any code.
as i am just guessing, even if the if is false, the else should run as it is running in my localhost.
the problem must be something with your sever.
put a error_reporting(E_ALL); on top it will show errors if it there.
else try writing in a new file.
<?php
error_reporting(E_ALL);
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$subject = $_REQUEST["My_Portfolio_Website"] ;
$message = $_REQUEST['message'] . "\nName: " . $name . "\nEmail: ".$email; "\n \nMessage: ".$message;
echo "<h1>Thank you for contacting me. I will get back to you ASAP!</h1>";
}else{
?>
<form method="post" action="contact.php" class="connect">
<div>
<input id="name" name="name" type="text" required>
<label for="name">Your Name</label>
</div>
<div>
<input id="email" name="email" type="text" required>
<label for="email">Your Email</label>
</div>
<div>
<textarea id="message" name="message" required></textarea>
<label for="message">Your Message</label>
</div>
<div class="metro">
<div class="metro-button" type="submit">Click me</div>
</div>
</form>
<?php
}
?>
I was able to figure this out by re-writing the original code I had based on the guide I used about a year ago, I came up with this for the answer which indeed works.
For all of the handling of where the information goes and how it was formated I included this chunk of php before I declared the doctype.
<?php
if($_POST["submit"]) {
$recipient="myemail#email.com";
$subject="Client Mail";
$name=$_POST["name"];
$email=$_POST["email"];
$email_from = $_POST['email'];
$message=$_POST["message"];
$mailBody="Name: $name\nEmail: $email\n\nMessage: $message";
mail($recipient, $subject, $mailBody, "From: $sender <$email>");
$thankYou="<p class='thank-you'>Thank you! Your message has been sent.</p>";
}
?>
From here, I figured out that the reason it wasn't submitting to it's own page was because my submit button was neither a button or input. I had it set as a div so with some tweaks here and there I rewrote the lower half to include an input as the submit. Which left me with this:
<?=$thankYou ?>
I included a small amount of text to display ( the $thankYou ) when you submit to the page and it reloads.
<form method="post" action="contact.php" class="connect">
<div>
<input id="name" name="name" type="text" required>
<label for="name">Your Name</label>
</div>
<div>
<input id="email" name="email" type="text" required>
<label for="email">Your Email</label>
</div>
<div>
<textarea id="message" name="message" required></textarea>
<label for="message">Your Message</label>
</div>
<div class="metro">
<input type="submit" name="submit" class="metro-button submit-me">
</div>
</form>
So now when submitted, the email comes in with:
The 'from' being set by $email
The 'subject' being set by $subject
and the message ($message) being formatted in this manner:
Name: John Doe
Email: JDoe#fake.com
Message: This is John Doe's message.
My apologies for the terrible question phrasing before hand, it was late at night and I was getting frustrated and losing my place, got a good nights rest and was able to solve it.
Here is the live version, I encourage you to test it, it works for me perfectly, hopefully this snippet can help someone else in the future!
I'm a total novice so please bear with me :)…I've managed to create a form and used PHP to send the data to an email address. However, once I click submit; the screen goes blank instead of staying on the current page and displaying a message. I'm guessing i'm missing some sort of PHP code?
Also, i'd like to use the JQuery validator plugin on my form, how can I add it without basically screwing up the form?
MY HTML:
<div>
<form id="form_id" name="form_name" action="scripts/index.php" method="post">
<div>
<label for="name">Name: </label>
<input type="text" name="name" id="name" placeholder="John Smith" required/>
</div>
<div>
<label for="email">Email: </label>
<input type="email" name="email" id="email" placeholder="name#mail.com" required/>
</div>
<div>
<label for="message">Message: </label>
<textarea name="message" id="message" rows="5" cols="30"></textarea>
</div>
<div>
<input id="submit" type="submit" name="submit" value="submit" />
</div>
</form>
<p id="feedback"><?php echo $feedback; ?></p>
</div>
MY PHP:
<?php
$to = 'example#gmail.com';
$subject = 'Message from The Rocket Factory';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$body = <<<EMAIL
Hi, my name is $name.
$message
From $name
My Address is $email
EMAIL;
$header = "From: $email";
if($_POST){
mail($to, $subject, $body, $header);
$feedback = 'Thanks for your message';
}
?>
PHP script that you create will return an empty page, because that script just to send email. I think you need to combine PHP script and HTML script together with PHP script in top of script to get that you want and edit form action to empty like this sample:
<?php
$to = 'example#gmail.com';
$subject = 'Message from The Rocket Factory';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$body = <<<EMAIL
Hi, my name is $name.
$message
From $name
My Address is $email
EMAIL;
$header = "From: $email";
if($_POST){
mail($to, $subject, $body, $header);
$feedback = 'Thanks for your message';
}
?>
<div>
<form id="form_id" name="form_name" action="" method="post">
<div>
<label for="name">Name: </label>
<input type="text" name="name" id="name" placeholder="John Smith" required/>
</div>
<div>
<label for="email">Email: </label>
<input type="email" name="email" id="email" placeholder="name#mail.com" required/>
</div>
<div>
<label for="message">Message: </label>
<textarea name="message" id="message" rows="5" cols="30"></textarea>
</div>
<div>
<input id="submit" type="submit" name="submit" value="submit" />
</div>
</form>
<p id="feedback"><?php echo $feedback; ?></p>
</div>
Your form will take the user to scripts/index.php. You are echoing the '$feedback' var on the page with the HTML form. Redirect from scripts/index.php using
header("location: filelocation");
exit();
You can achieve this in two ways :
1. Have php and html code in one page.
2. Use ajax to submit your form.
<div>
<form id="form_id" name="form_name" action="scripts/index.php" method="post">
<div>
<label for="name">Name: </label>
<input type="text" name="name" id="name" placeholder="John Smith" required/>
</div>
<div>
<label for="email">Email: </label>
<input type="email" name="email" id="email" placeholder="name#mail.com" required/>
</div>
<div>
<label for="message">Message: </label>
<textarea name="message" id="message" rows="5" cols="30"></textarea>
</div>
<div>
<input id="submit" type="submit" name="submit" value="submit" />
</div>
</form>
</div>
<?php
$to = 'example#gmail.com';
$subject = 'Message from The Rocket Factory';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$body = <<<EMAIL
Hi, my name is $name.
$message
From $name
My Address is $email
EMAIL;
$header = "From: $email";
if($_POST){
mail($to, $subject, $body, $header);
$feedback = 'Thanks for your message';
echo '<p id="feedback">'.$feedback.'</p>'; <-- Notice this..
}
?>
You can also use ajax in jquery ($.ajax) or javascript.