I never used PHP before, but I need to set up an HTML form from to be sent from my website to my gmail account. Checked some tutorials and came up with this code. But for some reason it is not working. When I hit submit it goes to a "Page Not Found
Looks like you've followed a broken link or entered a URL that doesn't exist on this site." Not sure what am I doing wrong.
I have my HTML document, and I have my PHP document. Saved together.
<form action="contact.php" method="POST" name="form">
<div class="row">
<div class="col-12 col-md-6">
<div class="contact-form">
<label for="name">Please enter your name:</label>
<input name="name" type="text" class="form-control" placeholder="Harry Potter">
</div>
</div>
<div class="col-12 col-md-6">
<div class="contact-form">
<label for="mail">Your email address:</label>
<input name="mail" type="email" class="form-control" placeholder="harry#potter.com">
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="contact-form">
<label for="message">How can I help you?</label>
<textarea name="message" class="form-control" id="form-text" cols="30" rows="10" placeholder="Let's do some magic"></textarea>
</div>
</div>
</div>
<div id="submit" class="text-center">
<button name="submit" type="submit" class="btn mt-5 mx-auto">Submit</button>
</div>
</form>
<?php
if(isset($_POST["submit"])) {
$name=$_POST["name"];
$mailFrom=$_POST["mail"];
$message=$_POST["message"];
$mailTo = "myaddress#gmail.com";
$subject = "Form from my website";
$headers = "From: ".$mailFrom;
$txt = "You have received an e-mail from ".$name."\n\n".$message;
if(mail($mailTo, $subject, $txt, $headers)) {
echo "<h1>I recieved your email! Will be in touch with you soon.</h1>";
}
else{
echo "<h1>Something went wrong! Try again.</h1>";
}
header("Location: https://www.whatever.com");
}
?>
Related
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
Having an issue with getting data from a form that I created and passing it into my email through php. Here's the link with the form http://kapena.github.io/pp_web/#contact-pp
Here's the exact issue..
When I click submit on the form button I get this error message saying..
I'm currently hosting this build on a gh-pages
I did some research on this and I found a patch for the error 405 but I have no idea how to implement this solution into my project. I am just a beginner and I need some instruction..Here's the solution I found https://gist.github.com/baskaran-md/e46cc25ccfac83f153bb#file-nginx-conf
How can I implement this solution correctly into my site?
Here's my php code so you can inspect that to see if there's and issue there thats causing this problem.
Any help would be greatly appreciated here..Trying to launch b4 the new year :)
<?php
if($_POST["submit"]) {
$recipient = "brentw.white#gmail.com"; //my email
$subject = 'Email message from Point Plumbing';
$name = $_POST ["yourName"];
$email = $_POST["yourEmail"];
$phone = $_POST["yourPhone"];
$location = $_POST["yourLocate"];
$message = $_POST["message-me"];
$mailBody="Name: $name\nEmail: $email\n\n$message";
$mail($recipient, $subject, $mailBody, "From: $name <$email>");
$thankYou="<p>Thank you! We will be in contact with you shortly.</p>";
}
?>
My HTML..I have a feeling it has something to do with method='post' possible that's the issue?
<form action="submit_form.php" method="post" id="spaceing" data-abide>
<div class="form-bg">
<div class="row">
<div id="name" class="large-6 medium-6 small-12 columns">
<label> <h5>Name</h5>
<input type="text" name="yourName" placeholder="What is you're name?"></input>
</label>
</div>
<div id="email" class="large-6 medium-6 small-12 columns">
<label><h5>Email</h5>
<input type="email" name="yourEmail" placeholder="Please enter in you're email."required></input>
</label>
<small class="error">An email Address is required.</small>
</div>
</div>
<div class="row">
<div id="phone"class="large-6 medium-6 small-12 columns">
<label><h5>Phone</h5>
<input type="text" name="yourPhone" placeholder="Please enter you're phone number."></input>
</label>
</div>
<div id="location" class="large-6 medium-6 small-12 columns">
<label><h5>Location</h5>
<input type="text" name="yourLocate" placeholder="Where on Oahu are you currently living?"></input>
</label>
</div>
</div>
<div class="row">
<div id="message-area" class="large-12 medium-12 small-12 columns">
<label><h5>Message</h5>
<textarea id="message" name="yourMessage" placeholder="Please tell us about you're plumbing issues."></textarea>
</label>
</div>
</div>
<div class="row">
<div id="submit" class="large-3 medium-3 small-3 columns">
<button type="submit-me">Submit</button>
</div>
</div>
</div>
</form>
look http://php.net/manual/en/function.mail.php
$mail($recipient, $subject, $mailBody, "From: $name <$email>");
$mail is not variable is function then
mail($recipient, $subject, $mailBody, "From: $name <$email>");
I modified your code and find lots of error.correct code is below:-
found following error on your code
1. use if(isset($_POST["submit"])) { instead of if($_POST["submit"]) {
2. you use wrong variable name for textarea. you should use $message = $_POST["yourMessage"]; instead of $message = $_POST["message-me"];
4. another error is your form action is at submit_form.php page but i found your mail code is at top of your page. if you want to submit to another page then use php code to submit_form.php page.
5. Main and important error of your code i found you using your gmail email at the place of sending mail.but you should use your domain email like brentw.white#kapena.github.io if you using another domain email these mail are count as suspicious and your mail goes to spam
I think it will be help full for you
I used your link here:-
http://smartzonewebservices.com/mtg/del.php
<?php
if(isset($_POST["submit"])) {
$recipient = "brentw.white#gmail.com"; //my email
echo $subject = 'Email message from Point Plumbing';
echo $name = $_POST ["yourName"];
echo $email = $_POST["yourEmail"];
echo $phone = $_POST["yourPhone"];
echo $location = $_POST["yourLocate"];
echo $message = $_POST["yourMessage"];
$mailBody="Name: $name\nEmail: $email\n\n$message";
mail($recipient, $subject, $mailBody, "From: $name <$email>");
echo $thankYou="<p>Thank you! We will be in contact with you shortly.</p>";
}
?>
<form action="" method="post" id="spaceing" data-abide>
<div class="form-bg">
<div class="row">
<div id="name" class="large-6 medium-6 small-12 columns">
<label> <h5>Name</h5>
<input type="text" name="yourName" placeholder="What is you're name?"></input>
</label>
</div>
<div id="email" class="large-6 medium-6 small-12 columns">
<label><h5>Email</h5>
<input type="email" name="yourEmail" placeholder="Please enter in you're email."required></input>
</label>
<small class="error">An email Address is required.</small>
</div>
</div>
<div class="row">
<div id="phone"class="large-6 medium-6 small-12 columns">
<label><h5>Phone</h5>
<input type="text" name="yourPhone" placeholder="Please enter you're phone number."></input>
</label>
</div>
<div id="location" class="large-6 medium-6 small-12 columns">
<label><h5>Location</h5>
<input type="text" name="yourLocate" placeholder="Where on Oahu are you currently living?"></input>
</label>
</div>
</div>
<div class="row">
<div id="message-area" class="large-12 medium-12 small-12 columns">
<label><h5>Message</h5>
<textarea id="message" name="yourMessage" placeholder="Please tell us about you're plumbing issues."></textarea>
</label>
</div>
</div>
<div class="row">
<div id="submit" class="large-3 medium-3 small-3 columns">
<button name="submit" type="submit">Submit</button>
</div>
</div>
</div>
</form>
I thing this going because you develop on github server and he does not allow make POST
change your code HTML:
<form action="submit_form.php" method="get" id="spaceing" data-abide>
and PHP change $_POST for $_GET but there is problem with length because all data is sending in URL.
If you want public page to normal server return back to POST method
Im not receiving emails from my email form.
I created a simple form that takes 4 fields and sends them to our emails. I tested my php code with no errors. I double checked the html to see if the script was referring properly which it was. I believe that the ids and names are correct. I also triple checked the variables I created on the php code. I've googled everything I could come up with no luck. Thanks!
var dump $body shows
Thank you! One of our station representatives will contact you soon.
string(119) "
Name: TEST
Email: test#emaol.com
Station: 1234
Message:
I need help with.
FORM
<form class="form-horizontal" role="form" method="post" action="feedback.php">
<fieldset>
<!-- Form Name -->
<legend>Our team will reach out to you as soon as possible.</legend>
<!-- Text input-->
<div class="control-group col-xs-4">
<label class="control-label" for="textinput">Full Name</label>
<div class="controls">
<input id="name" name="name" placeholder="John Doe" class="input-xlarge" type="text">
</div>
</div>
<!-- Text input-->
<div class="control-group col-xs-4">
<label class="control-label" for="textinput">E-Mail</label>
<div class="controls">
<input id="email" name="email" placeholder="affiliate.marketing.app#123.com" class="input-xlarge" type="text">
</div>
</div>
<!-- Text input-->
<div class="control-group col-xs-4">
<label class="control-label" for="textinput">Station Code</label>
<div class="controls">
<input id="station" name="station" placeholder="xxx" class="input-xlarge" type="text">
</div>
</div>
<!-- Textarea -->
<div class="control-group">
<label class="control-label" for="textarea">Message</label>
<div class="controls">
<textarea id="message" name="message">I need help with....</textarea>
</div>
</div>
<!-- Button -->
<div class="control-group">
<label class="control-label" for="submit"></label>
<div class="controls">
<button type="submit" id="submit" value="Send" name="singlebutton" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>
PHP PAGE
<?php
/* These are the variable that tell the subject of the email and where the email will be sent.*/
$emailSubject = 'Station App Support Request';
$mailto = 'myemail#domain.com, myemail2#domain.com';
/* These will gather what the user has typed into the fieled. */
$nameField = $_POST['name'];
$emailField = $_POST['email'];
$stationField = $_POST['station'];
$messageField = $_POST['message'];
/* This takes the information and lines it up the way you want it to be sent in the email. */
$body = <<<EOD
<br><hr><br>
Name: $nameField <br>
Email: $emailField <br>
Station: $stationField <br>
Message: $messageField <br>
EOD;
$headers = "From: $emailField\r\n"; // This takes the email and displays it as who this email is from.
$headers .= "Content-type: text/html\r\n"; // This tells the server to turn the coding into the text.
$success = mail($mailto, $emailSubject, $body, $headers); // This tells the server what to send.
?>
Having an issue with getting data from a form that I created and passing it into my email through php. Here's the link with the form http://kapena.github.io/pp_web/#contact-pp
Here's the exact issue..
When I click submit on the form button I get this error message saying..
I'm currently hosting this build on a gh-pages
I did some research on this and I found a patch for the error 405 but I have no idea how to implement this solution into my project. I am just a beginner and I need some instruction..Here's the solution I found https://gist.github.com/baskaran-md/e46cc25ccfac83f153bb#file-nginx-conf
How can I implement this solution correctly into my site?
Here's my php code so you can inspect that to see if there's and issue there thats causing this problem.
Any help would be greatly appreciated here..Trying to launch b4 the new year :)
<?php
if($_POST["submit"]) {
$recipient = "brentw.white#gmail.com"; //my email
$subject = 'Email message from Point Plumbing';
$name = $_POST ["yourName"];
$email = $_POST["yourEmail"];
$phone = $_POST["yourPhone"];
$location = $_POST["yourLocate"];
$message = $_POST["message-me"];
$mailBody="Name: $name\nEmail: $email\n\n$message";
$mail($recipient, $subject, $mailBody, "From: $name <$email>");
$thankYou="<p>Thank you! We will be in contact with you shortly.</p>";
}
?>
My HTML..I have a feeling it has something to do with method='post' possible that's the issue?
<form action="submit_form.php" method="post" id="spaceing" data-abide>
<div class="form-bg">
<div class="row">
<div id="name" class="large-6 medium-6 small-12 columns">
<label> <h5>Name</h5>
<input type="text" name="yourName" placeholder="What is you're name?"></input>
</label>
</div>
<div id="email" class="large-6 medium-6 small-12 columns">
<label><h5>Email</h5>
<input type="email" name="yourEmail" placeholder="Please enter in you're email."required></input>
</label>
<small class="error">An email Address is required.</small>
</div>
</div>
<div class="row">
<div id="phone"class="large-6 medium-6 small-12 columns">
<label><h5>Phone</h5>
<input type="text" name="yourPhone" placeholder="Please enter you're phone number."></input>
</label>
</div>
<div id="location" class="large-6 medium-6 small-12 columns">
<label><h5>Location</h5>
<input type="text" name="yourLocate" placeholder="Where on Oahu are you currently living?"></input>
</label>
</div>
</div>
<div class="row">
<div id="message-area" class="large-12 medium-12 small-12 columns">
<label><h5>Message</h5>
<textarea id="message" name="yourMessage" placeholder="Please tell us about you're plumbing issues."></textarea>
</label>
</div>
</div>
<div class="row">
<div id="submit" class="large-3 medium-3 small-3 columns">
<button type="submit-me">Submit</button>
</div>
</div>
</div>
</form>
look http://php.net/manual/en/function.mail.php
$mail($recipient, $subject, $mailBody, "From: $name <$email>");
$mail is not variable is function then
mail($recipient, $subject, $mailBody, "From: $name <$email>");
I modified your code and find lots of error.correct code is below:-
found following error on your code
1. use if(isset($_POST["submit"])) { instead of if($_POST["submit"]) {
2. you use wrong variable name for textarea. you should use $message = $_POST["yourMessage"]; instead of $message = $_POST["message-me"];
4. another error is your form action is at submit_form.php page but i found your mail code is at top of your page. if you want to submit to another page then use php code to submit_form.php page.
5. Main and important error of your code i found you using your gmail email at the place of sending mail.but you should use your domain email like brentw.white#kapena.github.io if you using another domain email these mail are count as suspicious and your mail goes to spam
I think it will be help full for you
I used your link here:-
http://smartzonewebservices.com/mtg/del.php
<?php
if(isset($_POST["submit"])) {
$recipient = "brentw.white#gmail.com"; //my email
echo $subject = 'Email message from Point Plumbing';
echo $name = $_POST ["yourName"];
echo $email = $_POST["yourEmail"];
echo $phone = $_POST["yourPhone"];
echo $location = $_POST["yourLocate"];
echo $message = $_POST["yourMessage"];
$mailBody="Name: $name\nEmail: $email\n\n$message";
mail($recipient, $subject, $mailBody, "From: $name <$email>");
echo $thankYou="<p>Thank you! We will be in contact with you shortly.</p>";
}
?>
<form action="" method="post" id="spaceing" data-abide>
<div class="form-bg">
<div class="row">
<div id="name" class="large-6 medium-6 small-12 columns">
<label> <h5>Name</h5>
<input type="text" name="yourName" placeholder="What is you're name?"></input>
</label>
</div>
<div id="email" class="large-6 medium-6 small-12 columns">
<label><h5>Email</h5>
<input type="email" name="yourEmail" placeholder="Please enter in you're email."required></input>
</label>
<small class="error">An email Address is required.</small>
</div>
</div>
<div class="row">
<div id="phone"class="large-6 medium-6 small-12 columns">
<label><h5>Phone</h5>
<input type="text" name="yourPhone" placeholder="Please enter you're phone number."></input>
</label>
</div>
<div id="location" class="large-6 medium-6 small-12 columns">
<label><h5>Location</h5>
<input type="text" name="yourLocate" placeholder="Where on Oahu are you currently living?"></input>
</label>
</div>
</div>
<div class="row">
<div id="message-area" class="large-12 medium-12 small-12 columns">
<label><h5>Message</h5>
<textarea id="message" name="yourMessage" placeholder="Please tell us about you're plumbing issues."></textarea>
</label>
</div>
</div>
<div class="row">
<div id="submit" class="large-3 medium-3 small-3 columns">
<button name="submit" type="submit">Submit</button>
</div>
</div>
</div>
</form>
I thing this going because you develop on github server and he does not allow make POST
change your code HTML:
<form action="submit_form.php" method="get" id="spaceing" data-abide>
and PHP change $_POST for $_GET but there is problem with length because all data is sending in URL.
If you want public page to normal server return back to POST method
I have a simple form with 3 fields, contact_name contact_email & contact_message when i submit this, the data entered into the form is not emailed to me. however if i check what is being posted i can see an array is posted:
Array
(
[contact_name] => paul
[contact_email] => test#test.com
[contact_message] => D;LKF'DSKF;LSDKF
)
Here is my form code:
<form role="form" name="form1" action="send_form_email.php" method="post">
<div class="row">
<div class="form-group col-xs-12 floating-label-form-group">
<label for="name">Name</label>
<input class="form-control" type="text" name="contact_name" placeholder="Name" id="contact_name">
</div>
</div>
<div class="row">
<div class="form-group col-xs-12 floating-label-form-group">
<label for="email">Email Address</label>
<input class="form-control" type="email" name="contact_email" placeholder="Email Address" id="contact_email">
</div>
</div>
<div class="row">
<div class="form-group col-xs-12 floating-label-form-group">
<label for="message">Message</label>
<textarea name="contact_message" placeholder="Message" class="form-control" rows="5" id="contact_message"></textarea>
</div>
</div>
<br>
<div class="row">
<div class="form-group col-xs-12">
<button type="submit" class="btn btn-lg btn-success">Send</button>
</div>
</div>
</form>
And here is the php script:
<?php
// Contact subject
$subject ='Message from Leeds Computers';
// Details
$message="$contact_message";
// Mail of sender
$mail_from="$contact_email";
// From
$header="from: $contact_name <$mail_from>";
// Enter your email address
$to ='test#gmail.com';
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "We've received your contact information";
}
else {
echo "ERROR";
}
?>
<? echo '<pre>';
print_r($_POST);
echo '</pre>';
?>
Any help would be much appreciated
You probably have to modify it to look at POST:
// Details
$message=$_POST["contact_message"];
// Mail of sender
$mail_from=$_POST["contact_email"];
// From
$header="from: " . $_POST["contact_name"] . " <$mail_from>";