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!
Related
I recently made a website using HTML, CSS, and JS. Since I don't know PHP, I am stuck at building the contact form where it is vital on the website. I learned a bit from YouTube tutorials and have the following HTML & PHP code:
<div class="contact_form">
<form action="/action_page.php">
<input type="text" id="name" name="name" placeholder="Name*">
<input class="contact_even" type="text" id="email" name="email" placeholder="Email id*">
<input type="text" id="phone" name="phone" placeholder="Phone No.">
<input class="contact_even" type="text" id="city" name="city" placeholder="City">
<textarea id="subject" name="subject" placeholder="How Can We Help You?"></textarea>
<input type="submit" value="Submit">
</form>
</div>
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mailFrom = $_POST['email'];
$phone = $_POST['phone'];
$city = $_POST['city'];
$message = $_POST['message'];
$mailTo = 'example#something.in';
$headers = 'From: '.$mailFrom;
$txt = $name.'('.$phone.') from '.$city.' says:\n\n'.$message;
$headers = "MIME-VERSION: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($mailTo, $headers, $txt);
header("Location: index.html?mailsent");
}
?>
Why do I need the MIME and content-type headers at the bottom as that bit I added from another tutorial.
When I use the form and try sending the message, I get the "?mailsent" after the URL but I receive no email which is a professional plan by GoDaddy.
They are also hosting my website. I contacted them to know whether the server allows me to make my contact form with the plan I have and they said yes. So, I must be missing something important here.
refer to the documentation of mail function
there are 3 required parameter : email destination (to), subject and the message, and two additional options are: headers and parameters.
your code didnt respect that, because you missing to add the subjuct as parameter.
and you get ?mailsent because you use header("Location: index.html?mailsent") without any test if the email send successfully or not.
i suggest you to replace the last two lines of your php code with this
$subject = "some subject"; // you can replace it with $subject = $_POST["subject"]
$result = mail($mailTo, $subject , $txt,$headers);
if ($result){
// mail send successfully
header("Location: index.html?mailsent");
} else {
// error
}
EDIT:
you can get the error message with error_get_last() function.
thanks to https://stackoverflow.com/a/20203870/195835
$subject = "some subject"; // you can replace it with $subject = $_POST["subject"]
$result = mail($mailTo, $subject , $txt,$headers);
if ($result){
// mail send successfully
header("Location: index.html?mailsent");
} else {
print_r(error_get_last());
}
You are missing the form action, So PHP doesn't know what to do with your variable data.Try adding method="post" inside <form> tag. Like this
<div class="contact_form">
<form action="/action_page.php" method="post">
<input type="text" id="name" name="name" placeholder="Name*">
<input class="contact_even" type="text" id="email" name="email" placeholder="Email id*">
<input type="text" id="phone" name="phone" placeholder="Phone No.">
<input class="contact_even" type="text" id="city" name="city" placeholder="City">
<textarea id="subject" name="subject" placeholder="How Can We Help You?"></textarea>
<input type="submit" value="Submit">
</form>
</div>
And also. If you use your computer as localhost(using xampp , wamp, or something without a hosting service) You have to make some changes to the config files.
Also try this modified php code
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mailFrom = $_POST['email'];
$phone = $_POST['phone'];
$city = $_POST['city'];
$message = $_POST['message'];
$title = "replace this";
$mailTo = 'support#udichi.in';
$txt = $name.'('.$phone.') from '.$city.' says:\n\n'.$message;
$headers = 'From: '.$mailFrom . PHP_EOL .'Reply-To:' .$mailFrom . PHP_EOL . 'X-Mailer: PHP/' . phpversion();
mail($mailTo,$title,$txt,$headers);
header("Location: index.html?mailsent");
}
?>
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
so I'm making a website for a customer and he wants me to make a contact us page, now I'm trying to make it say in the email message: "You have been contacted by $name $name2 and his email is $from. \n The message he wanted to say was in the subject of $message and the message is $message2" help?
my html code:
<form action="contactus.php" method="post">
<div class="form-group">
<label for="Subject">Subject*</label>
<input name="subject" class="form-control" id="subject1" placeholder="Subject">
</div>
<label for="sabject">Why do you want to contact us?</label>
<br>
<select name="select">
<option value="General Inquiry">General Inquiry</option>
<option value="hampion Guide Request">Champion Guide Request</option>
<option value="League of Legends Show(s) Request">League of Legends Show(s) Request</option>
<option value="Podcast - League of Legends">Podcast - League of Legends</option>
</select>
<label for="fname">First Name*</label>
<input type="text" name="firstname" class="form-control" id="namef" placeholder="First Name">
<label for="lname">Last Name</label>
<input type="text" name="lastname" class="form-control" id="namel" placeholder="Last Name">
<label for="email_adress">Email Adress*</label>
<input type="email" name="email_adress" class="form-control" id="email_adress" placeholder="Email Adress">
<label for="message">Message*</label>
<input name="message2" class="form-control" id="message" placeholder="message">
<input style="margin-top: 50px;" value="Send Form" name="submit" type="submit">Submit</button>
</form>
php:
<html>
<head>
<title> PHP script</title>
</head>
<body>
<?php
$to ="sudaiguy1#gmail.com";
$from = isset($_POST['email_adress']) ? $_POST['email_adress'] : '';
$email_subject = isset($_POST['subject']) ? $_POST['subject'] : '';
$message = isset($_POST['select']) ? $_POST['select'] : '';
$message2 = isset($_POST['message2']) ? $_POST['message2'] : '';
$name = isset($_POST['firstname']) ? $_POST['firstname'] : '';
if (empty($name)||empty($from))
{
echo "Name and email are mandatory!";
exit;
}
elseif (empty($email_subject)||empty($message)) {
echo "Your email or subject are blank, please write something in them";
exit;
}
elseif (empty($name)||empty($message2)) {
echo "Your name or message are empty";
exit;
}
$name2 = isset($_POST['lastname']) ? $_POST['lastname'] : '';
$email_from = "sudaiguy1#gmail.com";
$body = $_POST['You have been contacted by $name $name2 and his email is $from. \n The message he wanted to say was in the subject of $message and the message is $message2'];
$headers = "From: $body";
mail($to , $email_subject , $body ,$headers);
?>
</body>
</html>
My problem is that it says unidentified variables index or something like that
The undefined index comes from $body = $_POST['You have be..]
Try this for $body:
$body = 'You have been contacted by ' . $name . ' ' . $name2 . ', and his email is ' . $from . 'The message he wanted to say was in the subject of' . $message . ' and the message is ' . $message2;
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
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.
I am trying to create three forms. The way it should work is a form should appear and the user is able to input their info. When the submit button is pressed an email should be sent to the supervisor and the supervisor should click on a link and another form should appear. When the supervisor fills the form and then clicks submit an email should be submitted to the client. the client will click on the link and fill the form out. The client should be then able to send an email to the employee and the both the supervisor and the original user should be able to get the response. However when I keep creating the form the php keeps breaking after the second form. I cant seem to figure out why it keeps breaking in the third form.
here is a snippit of the php code for the second form:
if ($_POST['token'] == "2") {
$m = new mysql($connection_information);
$m->update('hello',array('approval'=>$_POST['approval'],
'comment'=>$_POST['comment'],
'approved_by'=>$_POST['approval_by'],
'approved_date'=>time()),'uid=\''.$_POST['uid'].'\'');
$records = $m->row(array('table' => 'hello','condition' => 'uid=\''.$_POST['uid'].'\''));
$eemail = records['email'];
$supemail = $records['supervemail'];
$clemail = $records['cemail'];
$approvaltime = date("m/d/y g:i a",$records['approved_date']);
$subject = " " . $clemail;
$headers = 'From: ' . $supemail . "\r\n" .
'Reply-To: ' . $supemail . "\r\n" .
'MIME-Version: 1.0' . "\r\n";
if($records['approval'] == 1){
$travel_action = 'approved';
}else{
$travel_action = 'rejected';
}
$message = " Travel Estimation ".$travel_action." on ".$approvaltime." by ".$records['approved_by']. "\r\n" . "Comment: " .$records['comment']. "\r\n";
mail($eemail, $subject, $message, $headers);
Here is my html portion:
<?php if ($_POST['token'] == "2") { ?>
<h1>Approval Decision Submited.</h1>
<?php } else if ($_POST['token'] == "1") {
echo "<h1>Form has been submitted</h1>";
} else {
if (isset($_GET['uid']) && isset($records)){
?>
<form id="approvalForm" name="form2" action="hello.php" method="POST">
<input type="hidden" name="token" value="2">
<input type="hidden" name="uid" value="<?php echo $_GET['uid'] ?>">
<fieldset>
<legend>Manager Approval Required</legend>
Submitted on: <?php echo date("m/d/y g:i a",$records['submitted']) ?><br/>
By: <?php echo $records['email'] ?><br/>
<label for="email">Supervisor's Email: </label>
<input type="text" name="email" title="Email" value="<?php echo $records['supervemail'] ?>"><br>
<label for="email">Client's Email: </label>
<input type="text" name="email" title="Email" value="<?php echo $records['supervemail'] ?>"><br>
<label for="email">Employee's Email: </label>
<input type="text" name="email" title="Email" value="<?php echo $records['supervemail'] ?>"><br>
<label for="approval_by">Please Enter your name for approval: </label>
<input type="text" name="approval_by" id="approval_by" title="Approved By" ><br>
<label for="approval">Please select appropriate action: </label>
<select name="approval" id="approval">
<option value="">Please Select Action</option>
<option value="1">Approval</option>
<option value="0">Rejection</option>
</select>
<label for="comment" >Comment: </label>
<input type="text" name="comment" id="comment" title="comment"><br>
<input class="submit" type="submit" value="Submit"/>
</fieldset>
</form>
In my third form I want the supervisor to send an email to the client so the that the client will receive the link and approve or disapprove in the third form. From there they can submit an email to the user if they agree or disagree. I made it so the third form looks almost identical to the second form. Is that where my fault lies?
I notice that the records array for the eemail variable does not have a dollar sign.
$eemail = records['email'];
Should be
$eemail = $records['email'];