I’m new to PHP so bear with me. My form is sending empty emails when I press submit. Any help would be great.
This is my form:
<form class="contact_form" action="kontakt.php" method="post">
<p><input type="text" required="required" id="name" name="name" class="text_input" value="" size="22" />
<label for="name">Namn *</label></p>
<p><input type="text" required="required" id="company" name="company" class="text_input" value="" size="22" />
<label for="company">Företag *</label></p>
<p><input type="email" required="required" id="email" name="email" class="text_input" value="" size="22" />
<label for="email">Epost *</label></p>
<p><textarea required="required" name="content" class="textarea" cols="30" rows="5"></textarea></p>
<p><button type="submit" class="button white"><span>Skicka</span></button></p>
<input type="hidden" value="info#web.se" name="contact_to"/>
</form>
And my PHP code so far is:
<?php
$name = $_POST['name'];
$company = $_POST['company'];
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
$content = $_POST['content'];
$mail_to = 'info#web.se';
$subject = 'Lilla form'.$name;
$body_message = 'From: '.$name."\n";
$body_message .= 'E-mail: '.$email."\n";
$body_message .= 'Message: '.$content;
$headers = 'From: '.$email."\r\n";
$headers .= 'Reply-To: '.$email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
?>
Please help me, I’m really stuck.
Thank you all!
Try this
<form class="contact_form" action="kontakt.php" method="post">
<p><input type="text" required="required" id="name" name="name" class="text_input" size="22" />
<label for="name">Namn *</label></p>
<p><input type="text" required="required" id="company" name="company" class="text_input" size="22" />
<label for="company">Företag *</label></p>
<p><input type="email" required="required" id="email" name="email" class="text_input" size="22" />
<label for="email">Epost *</label></p>
<p><textarea required="required" name="content" class="textarea" cols="30" rows="5"></textarea></p>
<p><button type="submit" class="button white"><span>Skicka</span></button></p>
<input type="hidden" value="info#web.se" name="contact_to"/>
</form>
Edit:(Debug)
$name = $_POST['name'];
$company = $_POST['company'];
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
$content = $_POST['content'];
echo $name.$comapny.$email.$content;exit; // check whether the values are posted successfully or not
Related
can anyone help me? I'm trying to prevent spam in the contact form.
I would like to achieve this with PHP. I can't find any solution on the web. Thanks in advance for who can help me out.
HTML
<form name="myForm" id="myForm" method="post" action="contact-form.php">
<input type="text" name="name" value="" class="form-control mt-3" id="name" placeholder="Full Name" required>
<input type="email" name="email" value="" class="form-control mt-3" id="email" placeholder="Email" required>
<textarea class="form-control mt-3" name="message" id="message" placeholder="Type your message" rows="7" required></textarea>
<input type="text" id="Nomoboto" name="Nomoboto" value="800 800 1000" autocomplete="off" />
<input type="text" id="PostItBoto" name="PostItBoto" value="93940" autocomplete="off" />
<input type="text" id="Empty_Me" name="Empty_Me" value=""/>
<input type="text" id="Empty_You" name="Empty_You" value=""/>
<button type="submit" class="btn btn-primary float-right mt-3">Send Message</button>
</form>
PHP
<?php
$name = $_POST ['name'];
$email = $_POST ['email'];
$message = $_POST ['message'];
$Empty_Me = $_POST ['Empty_Me'];
$Empty_You = $_POST ['Empty_You'];
$email_from = 'Contact Form';
$email_subject = "New Form Submission";
$email_body = "User Name: $name.\n".
"User Email: $email.\n".
"User Message: $message.\n".
"Empty_Me: $Empty_Me.\n".
"Empty_You: $Empty_You.\n";
function email_validation($str) {
return (!preg_match(
"^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^", $str))
? FALSE : TRUE;
}
$to = "info#mail.com";
$headers = "From $email_from \r\n";
mail($to,$email_subject,$email_body,$headers);
header("Location: index.html");
I have made a contact form that allows users to send me messages, but what I couldn't add is the ability for them to send me a file with it. Here is my code:
<form action="mail.php" method="post" enctype='multipart/form-data'>
<input type="text" class="feedback-input" id="firstname" name="firstname" placeholder="First Name" size="30" required="">
<br/>
<input type="text" class="feedback-input" id="lastname" name="lastname" placeholder="Last Name" size="30" required="">
<br/>
<input type="email" class="feedback-input" id="title" name="title" placeholder="E-mail" size="30" required="">
<br/>
<textarea name="message" class="feedback-input" placeholder="What can I help you with?" style="height: 150px;" required=""></textarea><br/>
<br/>
<input type="file" name="file" id="file" placeholder=" " tabindex="1" required/><br/>
<input type="submit" name="submit" id="Submit" value="Send">
and this is the mail.phph file:
<?php
$firstname = $_POST['firstname'];
$title = $_POST['title'];
$lastname = $_POST['lastname'];
$message = $_POST['message'];
$ip = $_SERVER['REMOTE_ADDR'];
$formcontent=" From: $firstname $lastname \n Email Address: $title \n IP: $ip \n\n Description : $message";
$recipient = "myemail#yahoo.com";
$subject = "New Message!!";
$mailheader = "From: $title \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header("Location: www.mythankyoupage.com");
die();
?>
For some reason whenever this script get's execited to the point where it is suppose to echo out "IT WORKED!", the message displays but the form that is suppose to be above it disapears.
My Code:
<?php
$message = $_REQUEST['message'];
$email = $_REQUEST['email'];
$times = $_REQUEST['times'];
$subject = $_REQUEST['subject'];
$to = $_REQUEST['to'];
for ($i=1; $i<=$times; $i++) {
mail( "$to", "$subject", $message, "From:" . rand() . "#$email" ) ;
}
?>
<form method="POST" id="email">
<h1>Email Bomber</h1>
<fieldset id="inputs">
<input name="times" type="text" placeholder="How Many Emails" autofocus required>
<input name="email" type="text" placeholder="Email Suffix" autofocus required>
<input name="to" type="email" placeholder="Who Do You Want To Email" autofocus required>
<input name="subject" type="text" placeholder="Email Subject" autofocus required>
<textarea name="message" placeholder="The Email Message" rows="15" cols="40"></textarea>
</fieldset>
<fieldset id="actions">
<input type="submit" id="submit" name="Send" value="Send Email">
</fieldset>
</form>
<?php
if (isset($_REQUEST['message'])) {
echo "IT WORKED!";
}
?>
Should be :
PHP code :
<?php
if (isset($_REQUEST['Send'])) {
$message = $_REQUEST['message'];
$email = $_REQUEST['email'];
$times = $_REQUEST['times'];
$subject = $_REQUEST['subject'];
$to = $_REQUEST['to'];
for ($i=1; $i<=$times; $i++) {
mail( "$to", "$subject", $message, "From:" . rand() . "#$email" ) ;
}
echo "IT WORKED!";
}
?>
HTML :
<form method="POST" id="email" action="#">
<h1>Email Bomber</h1>
<fieldset id="inputs">
<input name="times" type="text" placeholder="How Many Emails" autofocus required>
<input name="email" type="text" placeholder="Email Suffix" autofocus required>
<input name="to" type="email" placeholder="Who Do You Want To Email" autofocus required>
<input name="subject" type="text" placeholder="Email Subject" autofocus required>
<textarea name="message" placeholder="The Email Message" rows="15" cols="40"></textarea>
</fieldset>
<fieldset id="actions">
<input type="submit" id="submit" name="Send" value="Send Email">
</fieldset>
</form>
I’m new to PHP so bear with me. My form is sending empty emails when I press submit. Any help would be great.
This is my form:
<form class="contact_form" action="kontakt.php" method="post">
<p><input type="text" required="required" id="name" name="name" class="text_input" value="" size="22" />
<label for="name">Namn *</label></p>
<p><input type="text" required="required" id="company" name="company" class="text_input" value="" size="22" />
<label for="company">Företag *</label></p>
<p><input type="email" required="required" id="email" name="email" class="text_input" value="" size="22" />
<label for="email">Epost *</label></p>
<p><textarea required="required" name="content" class="textarea" cols="30" rows="5"></textarea></p>
<p><button type="submit" class="button white"><span>Skicka</span></button></p>
<input type="hidden" value="info#web.se" name="contact_to"/>
</form>
And my PHP code so far is:
<?php
$name = $_POST['name'];
$company = $_POST['company'];
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
$content = $_POST['content'];
$mail_to = 'info#web.se';
$subject = 'Lilla form'.$name;
$body_message = 'From: '.$name."\n";
$body_message .= 'E-mail: '.$email."\n";
$body_message .= 'Message: '.$content;
$headers = 'From: '.$email."\r\n";
$headers .= 'Reply-To: '.$email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
?>
Please help me, I’m really stuck.
Thank you all!
Try this
<form class="contact_form" action="kontakt.php" method="post">
<p><input type="text" required="required" id="name" name="name" class="text_input" size="22" />
<label for="name">Namn *</label></p>
<p><input type="text" required="required" id="company" name="company" class="text_input" size="22" />
<label for="company">Företag *</label></p>
<p><input type="email" required="required" id="email" name="email" class="text_input" size="22" />
<label for="email">Epost *</label></p>
<p><textarea required="required" name="content" class="textarea" cols="30" rows="5"></textarea></p>
<p><button type="submit" class="button white"><span>Skicka</span></button></p>
<input type="hidden" value="info#web.se" name="contact_to"/>
</form>
Edit:(Debug)
$name = $_POST['name'];
$company = $_POST['company'];
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
$content = $_POST['content'];
echo $name.$comapny.$email.$content;exit; // check whether the values are posted successfully or not
What is wrong with this code?
Here is the first page of the code:
<strong>Contact Form</strong><form name="form1" method="post" action="sendcontact.php">Subject:<input name="subject" type="text" id="subject" size="50">Detail:<textarea name="detail" cols="50" rows="4" id="detail"> </textarea>Name:<input name="name" type="text" id="name" size="50">Email:<input name="email" type="text" id="email" size="50"><input type="submit" name="Submit" value="Submit"><input type="reset" name="Submit2" value="Reset">
Here is the sendcontact.php page:
<?php $subject =$subject;$message =$detail;$mail_form =$email;$header ="from: $name<$mail_from>";mail("email#email.com",$subject,$message,$header);?>
To retrieve variables submitted from a POST form you must get their values from the $_POST array.
This should accomplish what you are after:
$subject = $_POST['subject'];
$message = $_POST['detail'];
$mail_from = $_POST['email'];
$header ="from: ".$_POST['name']."<$mail_from>";
mail("email#email.com",$subject,$message,$header);