How to add receiver address to my contact form - php

How to add receiver address to my contact form. I tried and searched a lot but i cant solve the issue by myself. help! Thx!!!
<article id="contact">
<h2 class="major">Contact</h2>
<form name="contactform" method="post" action="index.html">
<div class="fields">
<div class="field half">
<label for="name">Name</label>
<input type="text" name="name" id="name" />
</div>
<div class="field half">
<label for="email">Email</label>
<input type="text" name="email" id="email" />
</div>
<div class="field half">
<label for="email">Telefon</label>
<input type="text" name="telefon" id="email" />
</div>
<div class="field half">
<label for="email">Subject</label>
<input type="text" name="subject" id="email" />
</div>
<div class="field">
<label for="message">Message</label>
<textarea name="message" id="message" rows="4"></textarea>
</div>
</div>
<ul class="actions">
<li><input type="submit" value="Send Message" class="primary"/></li>
<li><input type="reset" value="Reset" /></li>
</ul>
</form>
</article>

Receiver mailId add at php side, you can pass receiver mailId as "to" filed in php mail function.
mail($to,$subject,$txt,$headers);
If you implement your sending mail in other way then send your php code

You need to update your action in form element
<form name="contactform" method="post" action="some_php_page.php">
and in some_php_page.php you need to add bellow code.
if(isset($_Post['name']){
$to = "Receiver Email Id ";
$subject = "Your Subject";
$name = trim($_POST['name']);
$email = $_Post['email'];
$telefon = $_Post['telefon'];
$subject = $_Post['subject'];
$message = $_Post['message'];
$body = "Name: ".$name.'\n';
$body .= "Email: ".$email.'\n';
$body .= "Subject: ".$subject.'\n';
$body .= "Message: ".$message.'\n';
mail($to,$subject,$body);
}
Hope this will help you...

Related

Bootstrap 4 form not sedning any messages

My bootstrap 4 form is not sending any messages, I've uploaded the index.php and contact.php files on the server and I'm not having any response. Would you be able to help me find the problem?
Landing page with simple form
<form id="#contacts" method="POST" class="form" role="form">
<div class="row">
<div class="col-md-6 form-group">
<input class="form-control" id="name" name="name"
placeholder="Podaj swoje Imię i nazwisko" type="text" required/>
</div>
<div class="col-md-6 form-group">
<input class="form-control" id="website" name="website"
placeholder="Adres strony www" type="text" required/>
</div>
<div class="col-md-6 form-group">
<input class="form-control" id="telephone" name="telephone"
placeholder="Podaj swój numer telefonu" type="text" required/>
</div>
<div class="col-md-6 form-group">
<input class="form-control" id="email" name="email"
placeholder="Podaj swój email" type="email" required/>
</div>
</div>
<textarea class="form-control" id="message" name="message" placeholder="Twoja wiadomość"
rows="4"></textarea>
<br>
<div class="row">
<div class="col-md-12 form-group">
<button class="btn btn-primary" type="submit">Wyślij</button>
</div>
</div>
</form>
contact.php
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$website = $_POST['website'];
$telephone = $_POST['telephone'];
$email_from = 'SEO';
$email_subject = 'Wiadomość kontaktowa z... '
$email_body = "Name: $name.\n".
"Email: $email.\n".
"Message: $message.\n";
"Website: $website.\n";
"Telephone: $telephone.\n";
$to = "biuro#of.pl";
$headers = "From: $email_from r\n";
$headers .= "Reply-To: $email r\n";
mail($to,$email-$email_subject,$email_body,$headers);
header("location: index.php");
?>
Your form is missing Action
<form id="#contacts" method="POST" class="form" role="form" action="contact.php">

PHP Contact form sending no content in emails

I need help, i'm trying to set up a contact form, I have the code and think I have it set up correctly with HTML and PHP. When I submit to test it on my testsite it send an email through but the email is blank.
Thanks in advance if you can help me please.
HTML:
<div class="col-md-6 contact-right">
<form name="contactform" action="mailer.php" method="post" role="form" enctype="text/plain">
<div class="styled-input agile-styled-input-top">
<input type="text" class="form-control" name="name" placeholder="Your Name">
<label for="name">Name</label>
<span></span>
</div>
<div class="styled-input">
<input type="text" class="form-control" name="email" placeholder="Your Email">
<label for="email">Email</label>
<span></span>
</div>
<div class="styled-input">
<input type="text" class="form-control" name="subject" placeholder="Subject">
<label for="subject">Subject</label>
<span></span>
</div>
<div class="styled-input">
<textarea class="form-control" rows="4" name="message" placeholder="Your message..."></textarea>
<label for="message">Message</label>
<span></span>
</div>
<input type="submit" value="Submit" name="submit">
</form>
</div>
<div class="clearfix"> </div>
</div>
</div>
</div>
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "laura#ironcladdesign.co.uk";
$subject = "Enquiry from CK9C Website";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! We will be in touch very soon";
?>
The problem is here:
<form name="contactform" action="mailer.php" method="post" role="form" enctype="text/plain">
You are encoding as "text/plain". Replace with "application/x-www-form-urlencoded" which is the default or don't include enctype and that will be the default.
you can try it in place of $_POST
if ((!is_array($_POST)) || (count($_POST) < 1)) {
$_POST = json_decode(file_get_contents('php://input'), true);
}

E-mail sending form php/html

I,m trying to make a form send an e-mail but im getting page not found error.
This is the form itself
<form action="sendmail.php" method="post">
<div>
<div class="row half">
<div class="6u">
<input type="text" class="text" name="name" placeholder="Name" />
</div>
<div class="6u">
<input type="text" class="text" name="email" placeholder="Email" />
</div>
</div>
<div class="row half">
<div class="12u">
<input type="text" class="text" name="subject" placeholder="Subject" />
</div>
</div>
<div class="row half">
<div class="12u">
<textarea name="message" placeholder="Message"></textarea>
</div>
</div>
<div class="row">
<div class="12u">
<input type="submit" class="button" value="Send Message" />
</div>
</div>
</div>
</form>
And this is the PHP file named sendmail.php
<?php
$to = "info#aroundgalaxy.pt";
$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
//$site = $_REQUEST['site'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$headers = "noreply#aroundgalaxy.pt";
$body = "From: $name \n\n Email: $email \n\n Message: $message";
$sent = mail($to, $subject, $body, $headers) ;
if($sent)
{echo "<script language=javascript>window.location = 'LINK BACK TO CONTACT PAGE';</script>";}
else
{echo "<script language=javascript>window.location = 'LINK BACK TO CONTACT PAGE';</script>";}
?>
Am i missing something?
Thanks
The code should work. I dont think there is a problem with the code. Just make sure both the form page & sendmail.php are on the same directory

HTML and PHP message form

I'm currently working on a HTML form that uses PHP to send a message to email. I'm testing in MAMP and am unable to get a response after clicking "send message". Any advice would be much appreciated.
HTML
<form action="mail.php" method="POST">
<div class="row half">
<div class="6u">
<input type="text" class="text" name="name" placeholder="Name" />
</div>
<div class="6u">
<input type="text" class="text" name="email" placeholder="Email" />
</div>
</div>
<div class="row half">
<div class="12u">
<textarea name="message" placeholder="Message" rows="6" cols="25"></textarea>
<br />
</div>
</div>
<div class="row">
<div class="12u">
<ul class="actions">
<li class="button form" input type="submit" value="Submit">Send Message</li>
</ul>
</div>
</div>
</form>
PHP
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$to = 'my#email.com';
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
$send_message=mail($to, $subject, $formcontent, $mailheader);
if($send_message){
echo "thank you"
} else {
echo "error";
}
?>
Thanks
found some errors in ur code
correct this:
<li class="button form" input type="submit" value="Submit">Send Message</li>
to
<li class="button form"> <input type="submit" value="Submit">Send Message</li>
correct this:
echo "thank you"
to echo "thank you";
Are you checking this in your local server? php mail() function may probably not work in local servers.Check it in some online servers(after correcting the bugs mentioned by #Ashish ).
HTML
<form action="mail.php" method="POST">
<div class="row half">
<div class="6u">
<input type="text" class="text" name="name" placeholder="Name" />
</div>
<div class="6u">
<input type="text" class="text" name="email" placeholder="Email" />
</div>
</div>
<div class="row half">
<div class="12u">
<textarea name="message" placeholder="Message" rows="6" cols="25"></textarea>
<br />
</div>
</div>
<div class="row">
<div class="12u">
<ul class="actions">
<li class="button form"> <input type="submit" value="Submit" name="sendmessage"/>Send Message</li> // Use name attribute
</ul>
</div>
</div>
*Use Name Attribute *
PHP
<?php
if($_POST['sendmessage']!="")
{
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$to = 'my#email.com';
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
$send_message=mail($to, $subject, $formcontent, $mailheader);
if($send_message){
echo "thank you";
} else {
echo "error"; }
}
?>
Try this code.

php email form issue

I am having trouble setting up a PHP form. Its my first try at doing this. I have got the form to submit and send to my email. But i receive 2 emails.
Is it ment to say (unknown sender) ???? surely not.
and in this image it shows you that after only one form submit. it send one blank email, and one with text. But only the message. Whats wrong?
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "adamgoredesign#gmail.com";
$subject = "New Message";
mail ($to, $subject, $message, "From: " . $name);
echo "Your Message has been sent";
?>
<form id="contactform" name="contact" method="post" action="#">
<div class="row">
<label for="name">Your Name<span class="req">*</span></label>
<input type="text" name="name" id="name" class="text" tabindex="1" placeholder="enter name" required>
</div>
<br>
<div class="row">
<label for="email">E-mail Address<span class="req">*</span></label>
<input type="email" name="email" id="email" class="text" tabindex="2" placeholder="address#domain.com" required>
</div>
<br>
<div class="row">
<label for="subject">Subject<span class="req">*</span></label>
<input type="text" name="subject" id="subject" class="text" tabindex="3" placeholder="subject title" required>
</div>
<br>
<div class="row">
<label for="message">Message<span class="req">*</span></label>
<textarea name="message" id="message" class="textarea" tabindex="4" required></textarea>
</div>
<br>
<div class="row">
<input type="submit" name="submit" value="Send Message" id="submit" />
</div>
</form>
The From header should be an email address or both a name and email address in the format:
From: John Smith <j.smith#gmail.com>
It should never be just a name, which is what you appear to be doing. Also remember to terminate headers with \r\n.
Using user input as the From header is not usually a good idea because it can introduce a header injection vulnerability, and it can also cause inconsistent spam filter results. For a contact form, I suggest just using a static email address of your own.

Categories