hi i have a self included email form so it doesn't require any other scripts i have run into a problem where i need it to send it via smtp but examples that i have seen are past my skill level i was wondering if some can help me
my email form is this:
<html>
<head>
<!--[if !IE]><!-->
<link rel="stylesheet" type="text/css" href="Register.css">
<!--<![endif]-->
</head>
<body style="background-color:#303030">
<?php
// display form if user has not clicked submit
if (!isset($_POST["submit"]))
{
?>
<div id="login">
<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
<input type="hidden" name="subject" value="can you create me an account"><br/>
Message: <textarea rows="10" cols="40" name="message"></textarea><br/>
first <input type="text" name="first_name" ><br/>
last <input type="text" name="last_name" ><br/>
company <input type="text" name="company" ><br/>
email <input type="text" name="email" ><br/>
Telephone number <input type="text" name="telnr" ><br/>
Description <input type="text" name="Description" ><br/>
<input type="submit" name="submit" value="Submit Feedback">
</form>
</div>
<?php
}
else
// the user has submitted the form
{
// Check if the "subject" input field is filled out
var_dump($_POST);
if (isset($_POST["subject"]))
{
$subject = $_POST["subject"];
$message = $_POST["message"];
$first = $_POST["first_name"];
$last = $_POST["last_name"];
$company = $_POST["company"];
$email = $_POST["email"];
$telnr = $_POST["telnr"];
$description = $_POST["Description"];
$therest = "First name= $first" . "\r\n" . "Last name= $last" . "\r\n" . "Company= $company" . "\r\n" . "Email= $email" . "\r\n" . "Telnr= $telnr" . "\r\n" . "Description= $description";
}
echo "$therest <br>";
$message = wordwrap($message, 700);
$first = wordwrap($first, 70);
$last = wordwrap($last, 70);
mail("receiver#whatever.co.uk",$subject,$name,$therest,"subject: $subject\n");
echo "Thank you for sending us feedback";
}
?>
</body>
</html>
The answer to this was no this form could not be changed into a SMTP email form what I needed to do was create a form that used PHPMailer and then I added the input boxes that I needed this has added more development into the website but it is actually working on the server that I was trying to reach
Related
Complete newbie at PHP. help.
I have written a large "join the club" form with 15 fields. the first 10 fields are required. last 5 are optional.
Each field has ID and names. name="fname" name="lname", for each field. (see below)___
<!-- FORM STARTS HERE -->
<form id="appliform" name="applform" method="post"
action="joinformscripts/test11.php"
enctype="text/plain" >
<!-- php code still in progress. test memb.php --->
<label for="fname">*First Name:</label><br>
<input type="text" id="fname" name="fname" required><br>
<label for="lname">*Last Name:</label><br>
<input type="text" id="lname" name="lname" required><br>
<label for="bizname">*Business Name:</label><br>
<input type="text" id="bizname" name="biz" required><br>
<label for="bizadd">*Business Mailing Address:</label><br>
<input type="text" id="bizadd" name="bizadd" required> <br>
<label for="city">*City:</label><br>
<input type="text" id="city" name="city" required> <br>
<label for="state">*State:</label><br>
<input type="text" id="state" name="state" required> <br>
<label for="zip">Zip:</label><br>
<input type="text" id="zip" name="zip" required> <br>
<label for="bizphone">*Business Phone:</label><br>
<input type="text" id="bizphone" name="bizphone" required> <br>
<label for="celphone">Personal Phone:</label><br>
<input type="text" id="celphone" name="celphone"> <br>
<label for="email">*Email:</label><br>
<input type="email" id="email" name="email" required><br>
<hr>
<h5>Complete this information if you are also paying for an Associate Membership. </h5>
<label for="fname">Associate First Name:</label><br>
<input type="text" id="afname" name="afname"><br>
<label for="lname">Associate Last Name:</label><br>
<input type="text" id="alname" name="alname"><br>
<label for="bizphone">Associate Business Phone:</label><br>
<input type="text" id="abizphone" name="abizphone" > <br>
<label for="celphone">Associate Personal Phone:</label><br>
<input type="text" id="acelphone" name="acelphone"> <br>
<label for="aemail">Associate Email:</label><br>
<input type="aemail" id="aemail" name="aemail"><br>
<hr>
<p>test 11 # 6.00p</p>
<!-- SEND BUTTON Submit using secure POST DATA button
when sent, opens remit payment page (in script)-->
<input type="submit" value="submit application" ><br>
<input type="reset" value="clear form">
<br>
<br>
<p>Please remit payment on the next page.</p>
</form> <!-- END MEMBERSHIP FORM with script action -->
PHP script.
<?php
// test 11
// after submit, goes to Remit page for payment: yes. //
// receive email with content in body: NO //
$email_to = "membership#xxxx.org";
$email_from = "membership#xxxx.org";
$reply_to = $_POST["email"];
$headers = "submitted by: .$mailfrom .$fname .$lname ";
$email_subject = "New Member Application Form (phptest8) revised 6.00pm thursday dec 10";
$headers = "From: " . $email_from . "\n";
$headers .= "Reply-To: " . $reply_to . "\n";
// NOT CAPTURING form variables.
//This needs to send all the fields in the form on Join page.
if(isset($_POST['submit'])){
$to = "membership#efwba.org"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['fname'];
$last_name = $_POST['lname'];
$subject = "Membership Form submission";
$message = $first_name . " " . $last_name . "
wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "my information " . $fname . "\n\n" . $fname . $lname . $biz . $bizadd . $city . $state . $zip . $bizphone . $celphone . $email . $afname . $alname . $abizphone . $acelphone. $aemail. $_POST['message'];
}
//Send the email. If the email is sent we will go to a REMIT PAYMENT page, if there is an error we will display a brief message.
ini_set("sendmail_from", $email_from);
$sent = mail($email_to, $email_subject, $email_body, $headers, $email_from);
if ($sent)
{
header("Location:/joinformscripts/thank-you-for-joining.html");
} else {
echo "There has been an error submitting your application. Please go back one page to verify all data has been entered correctly.";
}
// Function to validate against any email injection attempts
function IsInjected($str)
{
___
The host server -goDaddy, Cpanel- processes the php file and sends the email to the "Membership#" account.
After the form submits, it redirects to the Payment page, that part works!
However, I am NOT getting the field data inside the body of the email.
I see the starter line, but not what the applicant entered for contact info.
I want the body/ data to be a simple format, so I can copy it all and drop into a spreadsheet (for club mail merge printing)
It does not need to show the data labels.
I want to see this data in the email body:
"I want to join your organization!"
fname lname
biz
bizaddress
city state zip
bizphone
celphone
bizemail
QUESTION: what is the simplest method to capture each field into email_body?
Thank you!
I searched for a basic explanation and example on how to hide my html form "onsubmit" with basic php, while staying on the same page. I also needed to email the form results. I found bits here and there usually complicated and outside of my beginner abilities. So I am going to share a basic example of what I think is the easiest way to obtain this.
HTML Form with php:
<?php
session_start();
//if you require login start session first thing at top
?>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
</script>
</head>
<title>Example Form </title>
<?php
//my database connection is in insert.php
include_once 'insert.php';
//Set up email to receive the desired form results
$submit = $_POST['submit'];
$to = "youremail#yourdomain.com";
$email = "youremail#yourdomain.com";
$user = $_SESSION['yoursession']; #this is if require user login
$companyname = $_POST['companyname'];
$companyurl = $_POST['companyurl'];
$ipaddress = $_SERVER['REMOTE_ADDR']; #capture user's ip address
$subject = $companyname;
if(isset($submit) && !empty($companyname || $companyurl)){
$headers = 'From:'. $email . "\r\n"; // Sender's Email
//$headers .= 'Cc:'. $email . "\r\n"; // Carbon copy to Sender
$body = "
Company Name: $companyname \n\n Company URL: $companyurl \n\n User IP Address: $ipaddressadvertise
";
if(mail($to, $subject, $body, $headers)){
//What will show after submit button selected...
echo "Successfully submitted!" . "<br />";
echo "<br />" . "<strong>Company Name: </strong> " . " " . "$companyname" . "<br />" . "<strong>Company Website: </strong> " . " " . "$companyurl" . "<br />";
}else {
echo "Oops something went wrong. Try again or come back later. " . "<br />";
}
}
?>
<body>
<?php
//This is where you start to wrap what you want to hide onsubmit.
$submit = $_POST['submit'];
if(!isset($submit)){
//Do NOT put closing curly brace leave open and see below.
?>
<form id="form" name="form" action="" method="post" <?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>
<table border="0">
<tr>Company Name: <align = "center"><input type = "text" id = "companyname" name = "companyname" value = "" placeholder = "Required" required><br /><br />
<tr>Company Website: <align = "center"><input type = "text" id = "companyurl" name = "companyurl" value = "" placeholder = "Required" required><br /><br />
<input type="submit" name="submit" id="submit" onclick = "location.href='mailto:youremail#yourdomain.com';" value="Submit!">
<tr></tr><br /><br />
<tr></tr>
<tr></tr>
</form>
<?php
} //This is where you put your closing curly brace wrapping all of the information you want to hide when submit button is clicked.
?>
</body>
</html>
When the submit button is clicked the form should disappear, the message displays staying on the same page (without re-direct to another page) while emailing you the results.
NOTE: I tried this in the snippet and it didn't work. But I loaded it to a live site and it works perfectly without errors.
A basic structure can be something like that:
<?php
if (isset($_POST['submit'])) { // if submit - send email
$you = "YOUREMAIL";
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$comment = $_REQUEST['comment'];
mail($you, $subject, $comment, "From:" . $email); //send email
echo "Thank you for contacting us!"; //Email response
}
else { // else display the form:
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">
<label for="email">Email:
<input name="email" id="email" type="email" />
</label>
<label for="subject">Subject:
<input name="subject" id="subject" type="text" />
</label>
<label for="comment">Comment:
<textarea name="comment" id="comment" rows="15" cols="40"></textarea>
</label>
<input type="submit" value="Submit" />
</form>
<?php } ?>
I am trying to add a form into my index page, so that when you click on submit it will automatically return to the form when the page reloads. Right now if there are any errors on the page it will display them right above the form as well as give a little thank you message.
I currently have the following for the index.html page:
<?php
include "check.php";
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name:<br/> <input type="text" name="name" value="<?php echo $_POST['name']; ?>" size="30" /><br/><br/>
Email Address:<br/> <input type="text" name="email" value="<?php echo $_POST['email']; ?>" size="30"/> <br/><br/>
Company Name:<br/> <input type="text" name="companyName" value="<?php echo $_POST['companyname']; ?>" size="30" /> <br/><br/>
Message:<br/>
<textarea style="resize: none;" name="message" rows="5" cols="30"><?php echo $_POST['message']; ?></textarea>
<br/>
<input type="submit" name="Submit" />
</form>
When I submit the page it will run through the check.php file and verify all the data is good. It should then return the following If/Then statement if all the conditions are met.
if (!$errors) {
$mail_to = 'test#test.com';
$subject = 'New Mail from Form Submission';
$message = 'From: ' . $_POST['name'] . "\n";
$message .= 'Email: ' . $_POST['email'] . "\n";
$message .= 'Company Name: ' . $_POST['companyname'] . "\n";
$message .= "Message:\n" . $_POST['message'] . "\n\n";
mail($mail_to, $subject, $message);
echo "Thank you for your email!<br/><br/>";
$_POST = array(); //Clear form after submit
} else {
echo '<div style="color: red">' . $errors . '<br/></div>';
}
Is there anyway to add an auto-function during the "thank you" or "error" echos that will automatically bring the person back down to the contact form?
I hope I explained what I wanted to do correctly. If not please let me know and I will try to clarify it a bit better.
Add an ID to the form and append the anchor onto the form action URL
<form method="post" id="myform" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>#myform">
I am trying to add a form into my index page, so that when you click on submit it will automatically return to the form when the page reloads. Right now if there are any errors on the page it will display them right above the form as well as give a little thank you message.
I currently have the following for the index.html page:
<?php
include "check.php";
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name:<br/> <input type="text" name="name" value="<?php echo $_POST['name']; ?>" size="30" /><br/><br/>
Email Address:<br/> <input type="text" name="email" value="<?php echo $_POST['email']; ?>" size="30"/> <br/><br/>
Company Name:<br/> <input type="text" name="companyName" value="<?php echo $_POST['companyname']; ?>" size="30" /> <br/><br/>
Message:<br/>
<textarea style="resize: none;" name="message" rows="5" cols="30"><?php echo $_POST['message']; ?></textarea>
<br/>
<input type="submit" name="Submit" />
</form>
When I submit the page it will run through the check.php file and verify all the data is good. It should then return the following If/Then statement if all the conditions are met.
if (!$errors) {
$mail_to = 'test#test.com';
$subject = 'New Mail from Form Submission';
$message = 'From: ' . $_POST['name'] . "\n";
$message .= 'Email: ' . $_POST['email'] . "\n";
$message .= 'Company Name: ' . $_POST['companyname'] . "\n";
$message .= "Message:\n" . $_POST['message'] . "\n\n";
mail($mail_to, $subject, $message);
echo "Thank you for your email!<br/><br/>";
$_POST = array(); //Clear form after submit
} else {
echo '<div style="color: red">' . $errors . '<br/></div>';
}
Is there anyway to add an auto-function during the "thank you" or "error" echos that will automatically bring the person back down to the contact form?
I hope I explained what I wanted to do correctly. If not please let me know and I will try to clarify it a bit better.
Add an ID to the form and append the anchor onto the form action URL
<form method="post" id="myform" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>#myform">
Hey I have a simple coding issue and I am hoping someone can spot the error of my ways.
I have a contact page http://mattmcdougall.ca/contact
this page has a form that is connected to a form PHP.
it is half working, I receive the email with ONLY the name subject and recipient (me). I do not get the other information in the form. (phone number and content do not get placed in the email) ALSO, I want the website to bring the person filling out the form to http://mattmcdougall.ca/contactdone currently it goes to a blank form.php page
here is the form code and PHP code, please feel free to clean up PHP as I used a template I found online.
<form action="form.php" method="post" class="formtext">
<input name="Name" type="text" value="enter name" maxlength="60"><br>
<input name="Email" value="enter email" type="text"><br>
<input name="Phone Number" value="enter phone#"type="text"><br><br>
<textarea name="Interest" cols="60" rows="10">Interest?</textarea><br><input name="Submit" type="submit" value="Submit"><form
and the PHP
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Matt McDougall Photography</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<?php
$name = $_POST['name']; //senders name
$email = $_POST['email']; //senders e-mail adress
$phone = $_POST['phone'];
$recipient = "matt#mattmcdougall.ca"; //recipient
$mail_body = $_POST['interest']; //mail body
$subject = "interested client"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n";
mail($recipient, $subject, $mail_body, $phone, $header); //mail command :)
if(mail)
'http://mattmcdougall.ca/contactdone.html';
else
echo "Sorry Something Went Wonky, Please Try Again!";
?>
</BODY>
</HTML>
You're going to need to change the name of your form elements to match the params that you're expecting to receive via $_POST.
Right now you have (for example):
<input name="Phone Number" value="enter phone#"type="text"><br><br>
But you're going to need to name it:
<input name="phone" value="enter phone#"type="text"><br><br>
The name attribute is what is going to be submitted via the form to your PHP script. You need to use the same name on both sides.
Also what is the $phone variable in your mail function call? Those areas are reserved for additional headers and not just $phone. You'll need to concatenate the phone number into the $mail_body like so (with additional formatting of course):
$mail_body = $mail_body . " " . $phone;
This is the correct signature:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
Edit: In addition to all of this, your $header is also wrong as it's trying to use the $Name variable which does not exist. The $name variable does exist.
I think this below should solve your problems.
Form:
<form action="form.php" method="post" class="formtext">
<input type="text" name="name" placeholder="Enter Name" maxlength="60"><br>
<input type="text" name="email" placeholder="Enter Email"><br>
<input type="text" name="phone" placeholder="Enter Phone #"><br><br>
<textarea name="interest" cols="60" rows="10" placeholder="Interest?"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>
form.php
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$interest = $_POST["interest"];
$to = "matt#mattmcdougall.ca";
$subject = "Interested Client";
$headers = "From: {$name} <{$email}>\r\n";
$mail_body = <<<EMAIL
Name: {$name}
Phone: {$phone}
Message:
{$interest}
EMAIL;
$mail_success = mail($to, $subject, $mail_body, $headers);
if($mail_success) {
echo "http://mattmcdougall.ca/contactdone.html"; // are you trying to redirect to here?
} else {
echo "Sorry, something went wonky! Please try again!";
}
?>
HTTP POST variables are case sensitive, and the names of the input fields do not match that of those in PHP. <input type="text" name="datanamehere" /> with $_POST["datanamehere"]. Like what other answers said:
HTML:
<form action="form.php" method="post" class="formtext">
<input name="name" placeholder="Full name" type="text" maxlength="60"><br>
<input name="email" placeholder="Email" type="email"><br>
<input name="phone" placeholder="Phone number" type="tel"><br><br>
<textarea name="interest" placeholder="Interested in?" cols="60" rows="10"></textarea><br>
<input type="submit" value="Submit">
</form>
Notice I changed the value to placeholder, and used type="email" and type="tel".
form.php
$name = $_POST['name']; //senders name
$email = $_POST['email']; //senders e-mail adress
$phone = $_POST['phone'];
$recipient = "matt#mattmcdougall.ca"; //recipient
$mail_body = $_POST['interest']; //mail body
$subject = "interested client"; //subject
$header = "From: ". $name . " <" . $email . ">\r\n";
if (mail($recipient, $subject, $mail_body, $header)) //mail command :)
'http://mattmcdougall.ca/contactdone.html';
else
echo "Sorry Something Went Wonky, Please Try Again!";
As they said, mail() is a function returning a boolean. Wrap it around if to check for success.
Your element names do not match the ones in the PHP code and your form is not properly closed using .
<form action="form.php" method="post" class="formtext">
<input name="name" type="text" value="enter name" maxlength="60"><br>
<input name="email" type="text" value="enter email"><br>
<input name="phone" type="text" value="enter phone#"><br><br>
<textarea name="Interest" cols="60" rows="10">Interest?</textarea><br>
<input name="submit" type="submit" value="Submit">
</form>
mail is a function, so checking it in the 'if' by just writing mail isn't going to work.
try this instead
if(mail()):
// go to contactdone.html
header('Location: http://www.google.com');
exit();
else:
echo "Sorry Something Went Wonky, Please Try Again!";
endif;
Couple of things you can try,
if(mail)'http://mattmcdougall.ca/contactdone.html' is not going to do
anything, try using Header('Location
http://mattmcdougall.ca/contactdone.html')
Whenever you use $_POST the parameter name inside the [''] need to
match your input names (Example: <input name="interest" type="text">
would be $_POST['interest'])
If you want to show text inside an input use placeholder="enter
phone#" instead of value.