PHP Script Issues - Contact Form [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am writing a contact form for a website and am having trouble getting it to send the fields of my form on the actual e-mail.
The e-mails are sent and received successfully though.
Here is my HTML
<form action="mail.php" method="post" style="font-size:12px;">
<p>Name</p> <input type="text" name="name">
<p>Telephone</p><input type="text" name="phone" size="30" />
<p>Email</p> <input type="text" name="email">
<p>Message</p><textarea name="comments" rows="6" cols="25"></textarea><br />
<p>Best time to Contact You</p><input type="text" size="15" name="time" />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>
and my PHP
<?php
$to = "myemailaddress";
$subject = "New Website Enquiry";
$message = "You have recieved a new enquiry";
$from = $_POST['email'];
$name = $_POST['name'];
$message = $_POST['comments, phone, time'];
$headers = "From:" . $from;
$url = 'index.html';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
mail($to,$subject,$message,$headers);
?>

You need to learn basic PHP syntax.
$message = $_POST['comments, phone, time'];
is outright wrong. You cannot specify multiply array keys in a comma-separated list like that, let along within a STRING. The code should be more like:
$message = $_POST['comments'] . $_POST['phone'] . $_POST['time'];
Note that what you have is NOT a php-level syntax error. You're using a perfectly acceptable array key, which simply happens to not exist.

I found an syntax error in your code:
Change
$message = $_POST['comments, phone, time'];
to
$message = $_POST['comments'] . . $_POST['phone'] . $_POST['time'];
What else do you have a problem with?

<?php
$to = "myemailaddress";
$subject = "New Website Enquiry";
$message = "You have recieved a new enquiry";
$from = $_POST['email'];
$name = $_POST['name'];
$headers = "From:" . $from;
$url = 'index.html';
echo '<META HTTP-EQUIV=Refresh CONTENT="0;URL='.$url.'">'; mail($to,$subject,$message,$headers);
?>

Related

How can i do an echo pop up instead of opening in new tab? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I created an email form and after the submit button is pressed I want a pop up to appear, not open a new tab.
This is the form:
<form name="contactform" method="post" action="send_form_email.php">
<input class="inputForm" type="text" name="name" id="nameInput" placeholder="name*">
<input class="inputForm" type="text" name="email" id="emailInput" placeholder="email*">
<textarea name="message" placeholder="message*"></textarea>
<input id="submitButton" type="submit" name="submit">
</form>
And here is the php for it:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "myemail#gmail.com";
$subject = "New message";
mail ($to, $subject, $message, "From: " . $name);
echo "Your message has been sent!";
?>
This is technically an alert, but here you go!
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "myemail#gmail.com";
$subject = "New message";
mail ($to, $subject, $message, "From: " . $name);
echo('<script>
alert("Your message has been sent!")
</script>')
?>
I think this is what you were asking for, but if you were asking for something else, I hope you find it!

PHP form not working. Emails not sending [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I have a contact form on my website and it does not seem to be sending emails. It was on a server when I have been testing it.
Here is the form.
<form action="" method="post" name="form">
<input type="text" name="name" />
<input type="email" name="email" />
<textarea name="message" ></textarea>
<input name="submit" type="submit" value="Submit">
</form>
And here is the PHP code.
<?php
if(isset($_POST["submit"])){
if($_POST["name"]==""||$_POST["email"]==""||$_POST["message"]==""){
echo "Please fill in the contact form";
}else{
$to = "example#gmail.com";
$subject = "Contact Form";
$name= $_POST['name'];
$email= $_POST['email'];
$message= $_POST['message'];
$headers = "From: example#gmail.com";
mail($to,$subject,$name,$email,$message,$headers);
}
}
?>
I have changed my email address to a dummy one there but it does I have not recieved any emails when I do submit this form though.
Thanks in advance! :)
<?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);
//syntax mail(to,subject,message,headers,parameters);
?>
The php mail-function requires a different set of parameters:
Php Mail function
You have to embed $name and $email into your message before passing it to php's mail()

PHP Contact form to email [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I used this post to make a simple ‘contact us’ form. The form collects a few pieces of information (email, name and a message) from your visitor and emails it to you.
Instead of redirecting to a thank you page, I'd prefer it to just print the thank you (or error) text in the same HTML form page.
How can this be done? Where do I need to change to be able to keep the user in the same page and show the confirmation message ("Thank you")?
Edit: Found a much simpler way to do this - with ajax.
Here is my suggestion.
1- Change your file name contact-form.html to contact-form.php
2- Added include line and edit your form action in contact-form.php:
<h1>Contact us</h1>
<?php include './contact-form-handler.php'; ?>
<form method="POST" name="contactform" action="#">
3- Edit your contact-form-handler.php, disable header and added your thank you with personal message, you can also added some layout and decoration that is left to your fantasy.
//header('Location: contact-form-thank-you.html');
echo "Thank you " . $name . "<br />";
echo "We will contact you soon";
4- Last thing I will added condition to check if the form is submitted or not
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (empty... etc
}
5- (Optional) To re-fetch the posted values if failed I have added following to the form inputs (3 of them, each field got one with the respective field/variable name):
value="<?php if (isset($_POST['name'])) echo $name; ?>"
But in general When all this done, I will personally will go through the form and clean it up a little bit. Like if I am check the content in JavaScript it is not necessary to check if the fields are empty, so checking submission form is enough. I have not talk about form security yet against any kind of misuse, this just to make some thoughts when you come so far.
Complete code
Here is your final results, with extra things I done:
contact-form.php
<form method="POST" name="contactform" action="#">
<p>
<label for='name'>Your Name:</label> <br>
<input type="text" name="name" value="<?php if (isset($_POST['name'])) echo $name; ?>">
</p>
<p>
<label for='email'>Email Address:</label> <br>
<input type="text" name="email" value="<?php if (isset($_POST['email'])) echo $email_address; ?>"> <br>
</p>
<p>
<label for='message'>Message:</label> <br>
<textarea name="message" value="<?php if (isset($_POST['message'])) echo $message; ?>"></textarea>
</p>
<input type="submit" value="Submit"><br>
</form>
contact-form-handler.php
<?php
$errors = '';
$myemail = 'yourname#website.com';//<-----Put Your email address here.
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message'])
)
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address)
)
{
$errors .= "\n Error: Invalid email address";
}
if (empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. " .
" Here are the details:\n Name: $name \n Email: $email_address \n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to, $email_subject, $email_body, $headers);
//redirect to the 'thank you' page
//header('Location: contact-form-thank-you.html');
echo "Thank you " . $name . "<br />";
echo "We will contact you soon";
$name = "";
$email_address = "";
$message = "";
}
}
?>

what should I use to create a web contact form? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Hi guys this is my first question on stackoverflow.
I'm an amateur web designer designing a mostly static website..I need to create a contact form for user queries.What's the best approach for this task?
1)php's mailto function?
2)form data stored in a text file or spreadsheet?
3)database-connected(not preferred)
Any help would be really appreciated!!
To create a simple contact us form in php,you dont need to create any database. You have to use mail() function in PHP
You can refer following links to built simple contact us form :-
http://www.phpeasystep.com/phptu/8.html
http://www.freecontactform.com/email_form.php
OR
page1.php
<h2>Your Title</h2>
 
<form action="receiving.php" method="POST">
 
Name:<br><input type="text" name="name" size="40" /><br><br>
 
Email:<br><input type="text" name="email" size="40" /><br><br>
 
Phone:<br><input type="text" name="phone" size="40"><br><br>
 
Message:<br><textarea name="message" rows="3" cols="31" > </textarea><br><br>
 
<input type="submit" name="submit" value="Submit" />
<br><br>
 
</form>
receiving.php
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
if(isset($_POST['submit']))
{
$from_add = "contactform#yourwebsite.com";
$to_add = "yourname#yourwebsite.com";
$subject = "Your Subject Name";
$message = "Name:$name \n Email: $email \n Phone: $phone \n
Message: $message";
$headers = "From: $from_add \r\n";
$headers .= "Reply-To: $from_add \r\n";
$headers .= "Return-Path: $from_add\r\n";
$headers .= "X-Mailer: PHP \r\n";
if(mail($to_add,$subject,$message,$headers))
{
$msg = "Mail sent";
}
}
print "<p> Thank you $name for your message,
we will be in contact shortly. Click here
to continue </p>" ;
?>
NOTE :- You cannot send mail from localhost, configure some other smtp at localhost eg : google,yahoo...
Sample code of contact form using mail function
<?php
if (isset($_POST['action'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
if ($name == "" || $email == "" || $message == "") {
echo "All fields are required, please fill the form again.";
} else {
$from = "From: $name<$email>\r\nReturn-path: $email";
$subject = "Message sent using your contact form";
mail("youremail#yoursite.com", $subject, $message, $from);
echo "Email sent!";
}
}
?>
<form action="" method="POST">
Your name:<br>
<input name="name" type="text" /><br>
Your email:<br>
<input name="email" type="text"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" name="action" value="Send email"/>
</form>
Simply build a html-form and send the data to a php-file. Database is not needed at all, unless you want to store all messages or IP.
A simple search will get you a lot of results.
In the phpfile you have two options: Use php's mail() as is, or try PHPmailer. The latter is a bit more complecated, but ends up less as spam, it sets headers and everything for you.
Especially when you mail from multiple pointer on your website, I recommend PHPmailer.
In reply to one of your comments:
All mailing happends on the server. PHP is a serverside language, all actions take place on the server, not on the users computer. For that reason, your code should always be on a server, or local with WAMP (or LAMP)

How to send an html form to an email [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have this form:
<form class="contact-form" method="post" action="mailto:dre4311#gmail.com">
<p class="input-block">
<input type="text" name="name" id="name" placeholder="Name *" />
</p>
<p class="input-block">
<input type="email" name="email" id="email" placeholder="Email *" />
</p>
<p class="input-block">
<button class="button turquoise submit" type="submit" id="submit"><i class="icon-paper-plane-2"></i></button>
</p>
</form>
I would like to know, when people fill it how can I send the same filled details in the email?
<?PHP
$email = $_POST["emailaddress"];
$to = "you#youremail.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n
Email Address: $email";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: you#youremailaddress.com\n";
$usermessage = "Thank you for subscribing to our mailing list.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
?>
i wish may it's will help you .
Try this method
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent=" From: $name \n Website: $website \n Message: $message";
$recipient = "YOUREMAIL#HERE.COM";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
?>

Categories