Hi there im building a website and looking to connect a contact form to send an email/ message to an email address and im not quite sure what im doing wrong.
I'm very new so apologies and thank you in advance..
here's the code i have below!
PHP
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = 'tomasyoung0#gmail.com';
$headers = 'From: '.$mailFrom;
$txt = 'You have received an e-mail from '.$name.'. \n\n'.$message;
mail($mailTo, $subject, $txt, $headers);
header('Location: index.html?mailsend')
?>
HTML
<form class="contact-form" action="contactform.php" method="POST">
<input class="form-input" name="name" type="text" placeholder="Name" >
<input class="form-input" name="email" type="email" placeholder="Email">
<input class="form-input" name="subject" type="text" placeholder="Subject" >
<textarea class="form-input" placeholder="Message" cols="30" rows="10"></textarea>
<button class="btn"type="submit" name="submit">
<div class="button">
<i class="fa fa-paper-plane"></i><span class="send-text"></span>
</div>
</button>
</form>
You don't have mail and message at your html code, change
<input class="form-input" name="email" type="email" placeholder="Email">
To
<input class="form-input" name="mail" type="email" placeholder="Email">
And
<textarea class="form-input" placeholder="Message" cols="30" rows="10"></textarea>
To
<textarea class="form-input" name = "message" placeholder="Message" cols="30" rows="10"></textarea>
Inside [] of post variable you must put name of your input or button inside [] using ''
Related
I'm new to website building and was trying to get a contact form fully functional but for some reason, it's not sending any e-mails nor is it redirecting me back to the homepage. Would anyone be able to please tell me where I went wrong?
This is the HTML code:
<form action="form_contact.php" method="POST">
<div class="row">
<div class="input-group">
<input type="text" name="name" id="name" required>
<label for="name">...</label>
</div>
<div class="input-group">
<input type="text" name="number" id="number" required>
<label for="number">...</label>
</div>
</div>
<div class="input-group">
<input type="text" name="email" id="email" required>
<label for="email">...</label>
</div>
<div class="input-group">
<textarea id="message" name="message" rows="8" required></textarea>
<label for="message">...</label>
<input type="text" id="website" name="website"/>
</div>
<button type="submit" value="1" id="submit">...</button>
</form>
This is the PHP code:
<?php
if (isset($_POST['submit'])){
$nm = $_POST['name'];
$nb = $_POST['number'];
$mailFrom = $_POST['email'];
$msg = $_POST['message'];
if(!empty($_POST['website'])) die();
$mailTo='myemail#mail.com';
$headers= 'From: '.$mailFrom;
$txt= 'You have received a new e-mail from
'.$nm.'.\n\n'.$msg.'.\n\n'.$nb;
$mailSent=mail($mailTo, $txt, $headers);
if ($mailSent){
header('Location: mywebsite.com');
}}
I would greatly appreciate any help. Thank you.
I tried deleting the "website" field in the form since it's not even visible but that also didn't help.
html :
View/contactform.html
<form method="post" role="form" name="myemailform" action="sendingemail.php">
<div class="form-group">
<input type="text" name="name" class="form-control" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />
<div class="validation"></div>
</div>
<div class="form-group">
<input type="email" class="form-control" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" />
<div class="validation"></div>
</div>
<div class="form-group">
<input type="text" class="form-control" name="subject" id="subject" placeholder="Subject" data-rule="minlen:4" data-msg="Please enter at least 8 chars of subject" />
<div class="validation"></div>
</div>
<div class="form-group">
<textarea class="form-control" name="message" rows="5" cols="10" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea>
<div class="validation"></div>
</div>
<div class="text-center"><input type="submit" class="btn applyBtn" name="submit"/></div>
</form>
PHP:
view/sendingemail.php
<?php
$name = $_POST['name'];
$email_from = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$emails = "From: $email_from \r\n";
$emails .= "Name: $name \r\n";
$emails .= "Message: $message \r\n";
mail('sunitha_anilkumar#yahoo.com',$subject,$emails);
echo 'Mail sent!';
header('Location: thank-you.html');
?>
app.js
.when('/contactus', {
templateUrl: 'view/contactform.html',
controllerAs:'vm'
})
I wanted a contact form in my angular project and I given the form in view/contactform.html and sendingemail.php for submitting the form details. But when I submit the form, i am just seeing the sendingemail.php code , no form submission is done.Need assistance.
This means your webserver does not recognise your php file to be run as a php file. You might want to check your webserver's documentation to install and/or enable the PHP module.
I'm getting a http500 error with this code:
<?php
if(isset($_POST['submit'])){
$to = ["charlestdjames1#gmail.com"];
$subject = $_POST["name"];
$message = $_POST["content"];
$headers = $_POST["email"];
mail($to, $subject, $message, $headers);
}
?>
the logs state that I cannot use [] for reading, I'm not sure if this is a error with the code or not.
The form I'm using:
<form method="post">
<span class="close">x</span>
<label class="modalFont" for="name">Name:</label>
<input class="modalFont" type="text" id="name" name="name" placeholder="Please enter your name" /><br />
<label class="modalFont" for="email">Email Address:</label>
<input class="modalFont" type="text" id="email" name="email" placeholder="Please enter your email" /><br />
<label class="modalFont" for="message">Message:</label>
<input class="modalFont" type="text" id="message" name="content" placeholder="Enter your message here" /><br />
<button type="submit" id="submit">Submit</button>
</form>
I have a running form and it's half working. The form sends to my email address correctly but i'm having issues with the inputs not showing the text in the email. The only one that spits out any data is the message section.
The name, email, phone and website inputs are not spitting out any data and I can't figure out why?
// html5 code
<form action="forms/get_form.php" method="post">
<div>
<label for="name">Name</label>
<input type="text" id="name" placeholder="enter name" required="required">
</div>
<div>
<label for="email">Email</label>
<input type="email" id="email" placeholder="email address" required="required">
</div>
<div>
<label for="phone">Phone Number</label>
<input type="tel" id="phone" placeholder="enter phone number" required="required">
</div>
<div>
<label for="website">Enter website URL if you have one (optional)</label>
<input type="url" id="website" placeholder="website address">
</div>
<div>
<label for="message">Enter your message</label>
<textarea name="message" id="message" rows="10"></textarea>
</div>
<div>
<button type="submit" class="btn-blue">Send</button>
</div>
</form>
// php code
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$website = $_POST['website'];
$message = $_POST['message'];
$formcontent=" From: $name \n Email: $email \n Phone: $phone \n Website: $website \n Message: $message";
$recipient = "email goes here";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader);
if(mail) {
header('Location: /thankyou.html');
} else {echo "Email failed to send click back and check email details!";}
?>
Thanks in advance
Vizzy
Not ID but NAME param,
<input type="text" id="name" placeholder="enter name" required="required">
Should be:
<input type="text" name="name" placeholder="enter name" required="required">
Instead of ID, use name.
<input type="text" name="name" placeholder="enter name" required="required">
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.