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">
Related
I am not familiar with php. I have searched similar questions to where I could not find a solution. I followed a fairly simply tutorial to add a send email functionality to a web app but I cannot get it to work as I get this error when testing to send an email to my yahoo. I would like to ask for help in figuring out a solution and or how I can make this code better. Thanks in advance
This is my error
Cannot POST /contactform.php
Here is my form code from my index.html
<form action="contactform.php" method="post">
<div class="form-group">
<input type="text" name="name" placeholder="Full Name" class="form-control" id="name">
</div>
<div class="form-group">
<input type="text" name="email" placeholder="Email" class="form-control" id="email">
</div>
<div class="form-group">
<input type="text" name="subject" placeholder="Subject" class="form-control" id="message-text"></input>
</div>
<div class="form-group">
<textarea name="message" placeholder="Message" class="form-control" id="message-text"></textarea>
</div>
<button type="submit" name="submit" class="btn btn-outline-dark">Send message</button>
</form>
And here is my contactform.php that is in the same folder as my index.html
<?php
if (isset($_POST['submit'])){
$name = $_POST['name'];
$mailfrom = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$mailTo = "myemail#yahoo.com";
$headers = "From: ".$mailfrom;
$txt = "You have received an email from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.html?mailsend");
}
?>
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 unable to configure my email address on the submit button in this piece of code:
<div id="contact" class="spacer">
<div class="container contactform center">
<h2 class="text-center wowload fadeInUp">Get in touch with us</h2>
<div class="row wowload fadeInLeftBig">
<div class="col-sm-6 col-sm-offset-3 col-xs-12">
<form class="cmxform" id="commentForm" method="post" action="email.php">
<fieldset>
<input type="text" placeholder="Subject" id="csubject" name="subject" minlength="2" type="text" required>
<input type="text" placeholder="Email" id="cemail" type="email" name="email" required>
<textarea rows="5" placeholder="Message" id="ccomment" name="comment" required></textarea>
<input class="submit btn btn-primary" type="submit" value="Submit">
</fieldset>
</form>
</div>
</div>
I tried linking it to a php page (email.php), but it says server error. I don't know what to do. Can someone please help me?
To send an email you need the mail() function http://php.net/manual/en/function.mail.php
With your code you need to name the submit like name="submit" then inside action.php file you have to write something like this (or inside the same php where you have this code):
if(isset($_POST["submit"]))
{
//Remember to do input validations
$subject = $_POST["subject"];
$from = $_POST["email"];
$comment = $_POST["comment"];
$body = "User with email $from send the next comment: $comment";
//then here you set your email
$to = "myemail#email.com"; //change this
mail($to,$subject,$body);
}
This is only to explain some basic usage and set the variables you need, I advice you read also PHPmailer class
I've got 2 contact forms on a site. One is for simple contact-us and the other is for a registration. I've got them pointing to two different php and js files. The contact-us form is working, but I can't get the registration form to work. Here's the php:
<?php
// check if fields passed are empty
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phoneNumber']) ||
empty($_POST['childFirstName']) ||
empty($_POST['childLastName']) ||
empty($_POST['childAge']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['phoneNumber'];
$message = $_POST['childFirstName'];
$message = $_POST['childLastName'];
$message = $_POST['childAge'];
// create email body and send it
$to = 'lloyd.leeiv#yahoo.com';
$email_subject = "Contact form submitted by: $name";
$email_body = "You have received a new message. \n\n".
" Here are the details:\n \n Parent/Guardian Name: $name \n ".
"Email: $email_address \n Phone: $phoneNumber \n Child's Name: $childFirstName $childLastName \n Age: $childAge";
$headers = "From: JNGSO#jngso.com\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
And the HTML:
<form name="sentMessage" class="well" id="contactForm" novalidate>
<p>Parent/Guardian Name</p>
<div class="control-group">
<div class="controls">
<input type="text" class="form-control"
placeholder="Parent/Guardian Name" id="name" required
data-validation-required-message="Please enter your name" />
<p class="help-block"></p>
</div>
</div>
<p>Email Address</p>
<div class="control-group">
<div class="controls">
<input type="email" class="form-control" placeholder="Email"
id="email" required
data-validation-required-message="Please enter your email" />
</div>
</div>
<p>Phone Number</p>
<div class="control-group">
<div class="controls">
<input type="number" class="form-control" placeholder="Phone Number"
id="phoneNumber" required
data-validation-required-message="Please enter your phone number" />
</div>
</div>
<p>Child's First Name</p>
<div class="control-group">
<div class="controls">
<input type="text" class="form-control" placeholder="Child's First Name"
id="childFirstName" required
data-validation-required-message="Please enter your child's first name" />
</div>
</div>
<p>Child's Last Name</p>
<div class="control-group">
<div class="controls">
<input type="text" class="form-control" placeholder="Child's Last Name"
id="text" required
data-validation-required-message="Please enter your child's last name" />
</div>
</div>
<p>Child's Age</p>
<div class="control-group">
<div class="controls">
<input type="number" class="form-control" placeholder="Child's Age"
id="number" required
data-validation-required-message="Please enter your child's age" />
</div>
</div>
<p>Boy or Girl?</p>
<div class="control-group">
<label class="radio-inline">
<input type="radio" name="boyGirl" id="boy" value="Boy"> Boy
</label>
<label class="radio-inline">
<input type="radio" name="boyGirl" id="girl" value="Girl"> Girl
</label>
</div>
<div id="success"> </div>
<button type="submit" class="btn btn-lg btn-success pull-right">Send</button><br />
</form>
I've got the proper script links on the page (changed the name to point to the correct js file) and in the js file I'm pointing to the correct php url. Like I said, it works with the contact-us form but not this one. I can't figure out what I'm missing!
Okay, so I threw this question up in desperation (because I'm new to php and I didn't think I could solve it). After carefully examining it, it's actually pretty simple! doh!
I just had to make sure all of the id's were labeled, all of the var were accounted for and everything matched up in my php. For example, you can see above I have:
....
$message = $_POST['phoneNumber'];
$message = $_POST['childFirstName'];
$message = $_POST['childLastName'];
$message = $_POST['childAge'];
....
in my php where I should have each of those labeled differen't (not each one as $message).
I'm sorry if this wasted anyone's time, but hopefully someone can find this useful.
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