PHP mail script not sending to my email - php

i have setup a form than when pressed the image submit button it sends the filled form to the buisness email.
Here is the script i have used for php linked from my html.
<?php
if(isset($_POST['submit'])) {
$emailbody = 'First Name = '.$_POST['Name']."\n"
.'Surname = '.$_POST['SName']."\n"
.'Email = '.$_POST['email']."\n"
.'Contact Number = '.$_POST['tel_no']."\n"
.'Adress Line 1 = '.$_POST['address_line_1']."\n"
.'Adress Line 2 = '.$_POST['address_line_2']."\n"
.'Town/City = '.$_POST['town_city']."\n"
.'County = '.$_POST['county']."\n"
.'Post Code = '.$_POST['Post_code']."\n"
.'Newsletter = '.$_POST['newsletter']."\n"
.'Events = '.$_POST['events']."\n"
mail('My email#gmail.com', 'Order Form', $emailbody);
} else {
header('location: Payment.html');
}
?>
The form on the html has been linked via a action. is there anything wrong with the script?
PS on pressing the image it is then forwarded to paypal payment page.
Cheers
Edit:
Here is the HTML Code:
<form name="form1" method="post" action="PaymentFormmail.php" align="left">
<section>
<h1>Basic Infomation:</h1>
<p>
<label for="SName">First Name:</label>
<input type="text" name="Name" id="Name" style="margin-left:50px;">
</p>
<p>
<label for="SName">Surname:</label>
<input type="text" name="SName" id="SName" style="margin-left:64px;">
</p>
<p>
<label for="email">Email Address</label>
<input type="text" name="email" id="email" style="margin-left:28px;">
</p>
<p>
<label for="tel_no">Contact Number:</label>
<input type="text" name="tel_no" id="tel_no" style="margin-left:14px;">
</p>
</section>
<section>
<h1>Billing Infomation:</h1>
<p>
<label for="address_line_1">Address line 1:*</label>
<input name="address_line_1" type="text" id="address_line_1" align="right" style="margin-left:20px;">
</p>
<p>
<label for="address_line_2">Address Line 2: </label>
<input type="text" name="address_line_2" id="address_line_2"style="margin-left:20px;">
</p>
<p>
<label for="town_city">Town/City:*</label>
<input type="text" name="town_city" id="town_city"style="margin-left:55px;">
</p>
<p>
<label for="county">County:*</label>
<input type="text" name="county" id="county"style="margin-left:73px;">
</p>
<p>
<label for="Post_code">Post Code:*</label>
<input type="text" name="Post_code" id="Post_code"style="margin-left:46px;">
</p>
<h1>News and Events:</h1>
<p>
<input name="newsletter" type="checkbox" id="newsletter" value="Yes">
<label for="newsletter">I wish to receive the monthly newsletter from Monster Computers UK</label>
</p>
<p>
<input name="events" type="checkbox" id="events" value="Yes">
<label for="events">I wish to receive any infomation about upcomming events</label>
</p>
</section>
</form>
<p>By Clicking Pay now you agree to the Terms of Service</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="monstercomputeruk#gmail.com">
<input type="hidden" name="lc" value="GB">
<input type="hidden" name="item_name" id="byoName" value="0">
<input type="hidden" name="amount" id="finalpaypal">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest">
<input name="submit" type="image" onClick="MM_validateForm('Name','','R','SName','','R','email','','R','address_line_1','','R','town_city','','R','county','','R','Post_code','','R');return document.MM_returnValue" src="images/buttons/Pay Now.png" alt="PayPal — The safer, easier way to pay online." border="0">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>

Try changing
if(isset($_POST['submit']))
to
if(isset($_POST['SName']))
I think $_POST['submit'] doesn't work..
If this also fails then it means that the information isn't sent to your script.
In this case show us your html for the form used in the script.
EDIT
Using if(isset($_POST['submit'])) to not display echo when script is open is not working
EDIT AFTER HTML
in your javascript function called MM_validateForm
send your information using jquery POST to your mail script and remove the if clause checking if isset.
$.post("test.php", { name: "John", time: "2pm" } );
http://api.jquery.com/jQuery.post/
See examples section.

Related

On form submit, pass email address from first form to second form

I have two forms, the first gets submitted then the page reloads and shows the second. The problem I have is passing the email address from the first form to the second one. What's the best way to do this without interfering with my actions or changing it from POST to GET?
<?php if(!isset($_POST['crowd_email'])){ ?>
<form id="form" method="POST" action="<?php require( COMMON_PATH . '/components/crowdfunding.php' ); ?>">
<input type="text" name="crowd_email" class="crowd_email" value="" placeholder="Email address">
<input type="submit" class="register-btn" value="Register Interest" name="submit">
</form>
<?php } else { ?>
<form id="form" method="POST" action="<?php require( COMMON_PATH . '/components/crowdfunding-extra.php' ); ?>">
<input type="text" name="first_name" class="crowd_email extra-info" value="" placeholder="First name">
<input type="text" name="tel_no" class="crowd_email extra-info" value="" placeholder="Telephone number">
<input type="text" name="amount" class="crowd_email extra-info" value="" placeholder="Amount to invest">
<input type="submit" class="register-btn" value="Register Interest" name="submitextra">
</form>
<?php } ?>
1) Add a hidden field to the second form.
2) Add the value of the email address (submitted from the first form) to the hidden field when rendering the second form.
e.g.
<?php if(!isset($_POST['crowd_email'])){ ?>
<form id="form" method="POST" action="<?php require( COMMON_PATH . '/components/crowdfunding.php' ); ?>">
<input type="text" name="crowd_email" class="crowd_email" value="" placeholder="Email address">
<input type="submit" class="register-btn" value="Register Interest" name="submit">
</form>
<?php } else { ?>
<form id="form" method="POST" action="<?php require( COMMON_PATH . '/components/crowdfunding-extra.php' ); ?>">
<input type="text" name="first_name" class="crowd_email extra-info" value="" placeholder="First name">
<input type="text" name="tel_no" class="crowd_email extra-info" value="" placeholder="Telephone number">
<input type="text" name="amount" class="crowd_email extra-info" value="" placeholder="Amount to invest">
<input type="hidden" name="email" value="<?php echo $_POST["crowd_email"]; ?>" />
<input type="submit" class="register-btn" value="Register Interest" name="submitextra">
</form>
<?php } ?>
That way, when you submit the second form, the email field will be submitted along with the rest of the new data.
You can just add a hidden input in the second form containing the email value and give it the value from the first submission
<?php if(!isset($_POST['crowd_email'])){ ?>
<form id="form" method="POST" action="<?php require( COMMON_PATH . '/components/crowdfunding.php' ); ?>">
<input type="text" name="crowd_email" class="crowd_email" value="" placeholder="Email address">
<input type="submit" class="register-btn" value="Register Interest" name="submit">
</form>
<?php } else { ?>
<form id="form" method="POST" action="<?php require( COMMON_PATH . '/components/crowdfunding-extra.php' ); ?>">
<!-- New line to hold the email invisbly -->
<input type="hidden" name="crowd-email" value="<?php echo $_POST['crowd_email']; ?>"/>
<input type="text" name="first_name" class="crowd_email extra-info" value="" placeholder="First name">
<input type="text" name="tel_no" class="crowd_email extra-info" value="" placeholder="Telephone number">
<input type="text" name="amount" class="crowd_email extra-info" value="" placeholder="Amount to invest">
<input type="submit" class="register-btn" value="Register Interest" name="submitextra">
</form>
<?php } ?>

PHP - how to submit Paypal details to intermediate class

I currently have a form on my Wordpress shop which submits details to Paypal using the "Buy Now" button API. What I would like to do is based on the 'School' my customer selects on the form, I would like to submit the related Paypal e-mail address. I am currently storing the e-mail address related to the school in my database, so all I need to do is a SELECT from my database based on the selected school name.
I'd like to do this by submitting the form to a PHP class which then forwards the information to the Paypal API. My question is, as a PHP newbie, how do I do this? Here's the form code I have... how do I forward these fields to another PHP class which collects the selected dropdown field value and submits to Paypal?
Thanks in advance!!
<?php
class Template {
public function __construct() {
}
public function getForm($project_list, $business){
$require_mark = '<strong style="color:red;">*</strong>';
?>
<div id="payment_booking_main">
<form name="_xclick" id="payment_booking_form" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- <form name="_xclick" id="payment_booking_form" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> -->
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="hosted_button_id" value="7ACDDDD4URDK2" />
<!-- This is the paypal email that is sent. -->
<input type="hidden" name="business" value="<?php echo $business; ?>" />
<input type="hidden" name="a3" value="1">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="D">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" id="payment_booking_return_url" name="return" value="" />
<input type="hidden" id="payment_booking_notify_url" name="notify_url" value="">
<input type="hidden" id="payment_booking_total_amount" name="amount" value="0">
<input type="hidden" id="payment_booking_item_name" name="item_name" value="">
<input type="hidden" id="payment_booking_item_number" name="item_number" value="">
<!-- Where the project name option input is populated on form load -->
<div id="payment_booking_project_selectform">
<div class="payment_booking_line" style="heigth:20px !important;">
<span class="payment_booking_label">Project :</span>
<select id="payment_booking_project" name="payment_booking_project">
<?php
global $wpdb;
$sql = "SELECT * FROM `{$wpdb->prefix}payment_booking_project` WHERE project_status =1";
$project_list = $wpdb->get_results($sql);
foreach($project_list as $project){
echo '<option value="'.$project->id.'" amount="'.number_format($project->project_amount, 2).'" description="'.$project->project_description.'" price="'.$project->project_price.'">'.$project->project_name.'</option>';
}
?>
</select>
<span id="payment_booking_project_description" style="font-size:12px;"></span>
</div>
</div>
<div id="payment_booking_project_list"></div>
<div class="payment_booking_line">
<span class="payment_booking_label">Name <?php echo $require_mark; ?> :</span>
<span class="payment_booking_input"><input type="text" id="payment_booking_name" name="payment_booking_name" class="required" /></span>
</div>
<div class="payment_booking_line">
<span class="payment_booking_label">Address <?php echo $require_mark; ?> :</span>
<span class="payment_booking_input"><textarea id="payment_booking_address" name="payment_booking_address" class="required"></textarea></span>
</div>
<div class="payment_booking_line">
<span class="payment_booking_label">Home Phone Number :</span>
<span class="payment_booking_input"><input type="text" id="payment_booking_phone" name="payment_booking_phone" /></span>
</div>
<div class="payment_booking_line">
<span class="payment_booking_label">Email Address <?php echo $require_mark; ?> :</span>
<span class="payment_booking_input"><input type="text" id="payment_booking_email" name="payment_booking_email" class="required" /></span>
</div>
<div class="payment_booking_line">
<center>
<img id="img_submit" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" alt="PayPal — The safer, easier way to pay online." />
</center>
</div>
</form>
</div>
<?php
}
}
?>

Paypal buy now form with sending emails

I have a form that collects data on a persons car (year, color, class, last 4 digits of vin. That same form also has information on the person registering for this event.
When the user clicks the paypal buy now button it should send an email to the person who is accepting the forms as well as redirect the user to paypal so the user can pay the registration fee.
You will see a submit button as well as a buy now button. I basically want the functionality of the submit but the redirection to paypal like the buy now button. Also not sure what the action should be on the form.
<div id="container">
<section id="register">
<form action="mail.php" method="post" accept-charset="utf-8" on>
<h4>Your Jeep</h4>
<div class="form-field">
<fieldset>
<label>Year</label>
<input value="" placeholder="Year" type="text" name="year">
</fieldset>
<fieldset>
<label>Color</label>
<input value="" placeholder="Color" type="text" name="color">
</fieldset>
<fieldset>
<label>Class</label>
<input value="" placeholder="Stock, Modified, Highly Modified" type="text" name="class">
</fieldset>
<!--------------------
<div class="form-field">
<fieldset>
<label>Class</label>
<select class="form-field">
<option value="Select Class">Select Class</option>
<option value="Stock">Stock</option>
<option value="Modified">Modified</option>
<option value="Highly Modified">Highly Modified</option>
</select>
</fieldset>
</div>
------------------------->
<fieldset>
<label>Last 4 digits of VIN</label>
<input value="" placeholder="Last 4 digits of VIN" type="text" name="vin">
</fieldset>
</div>
<h4>You</h4>
<div class="form-field">
<fieldset>
<label>Name</label>
<input value="" placeholder="Name" type="text" name="name">
</fieldset>
</div>
<div class="form-field">
<fieldset>
<label>Address</label>
<input value="" placeholder="Address" type="text" name="address">
</fieldset>
</div>
<div class="form-field">
<fieldset>
<label>City</label>
<input value="" placeholder="City" type="text" name="city">
</fieldset>
</div>
<div class="form-field">
<fieldset>
<label>State</label>
<input value="" placeholder="State" type="text" name="state">
</fieldset>
</div>
<div class="form-field">
<fieldset>
<label>Zip</label>
<input value="" placeholder="Zip" type="text" name="Zip">
</fieldset>
</div>
<div class="form-field">
<fieldset>
<label>Email</label>
<input value="" placeholder="Email" type="text" name="email">
</fieldset>
</div>
<div class="form-button">
<input type="submit" onclick="this.form.submit();"></div>
</form>
<div id="paykim">
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="me#mybusiness.com">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="Jeep Registration">
<input type="hidden" name="amount" value="10.00">
<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
<p>Clicking the Submit button will bring you to the official PayPal website where you will be able to send the $10 Registration Fee to </p>
<p id="ekim">Email of person accepting the registrations.</p>
<p id="confirm">You'll recieve a conformation email once your transaction is complete.</p>
</div>
</section>
</div>
http://jsfiddle.net/BsVv5/
I assume you will be store the data in a database. I recommend that first save your form data in the database, Once stored, create a checkout page by querying the database and creates the additional form of paypal. you will require documentation of ipn paypal for sending instant notifications.
https://developer.paypal.com/webapps/developer/docs/classic/products/instant-payment-notification/

formname.submit not working on IE8

I am currently developing an app and i am getting difficulties on IE8.
I have the following code:
<form class="fillClaimForm" name="fillClaimForm" method="POST" enctype="multipart/form-data" action="<?php print BASE_URL; ?>?action=insertBlogger" >
<label for="fblogName">Blog's name: </label>
<input type="text" name="fblogName" id="fblogName" class="cfInput" placeholder ="Complex" required />
<label for="fblogUrl">URL: </label>
<input type="text" name="fblogUrl" id="fblogUrl" class="cfInput" placeholder ="www.complex.com" required />
<label>Blog's logo: </label>
<div class="upload-file-container"><span>UPLOAD</span>
<input type="file" name="fblogLogo" id="fblogLogo"/>
<p class="ErrLoad error" style="display:none;">Please load your logo</p>
</div>
<label for="fEmail">Email adresse: </label>
<input type="email" name="fEmail" id="fEmail" class="cfInput" required />
<label for="frNum">Phone number: </label>
<input type="tel" name="frNum" id="frNum" class="cfInput" required />
<input type="hidden" name="idVid" id ="idVid" value=""/>
<input type="hidden" name="idRubrique" id ="idRubrique" value=""/>
<button id="sendClaim" class="sendClaim">SEND</button>
Consequently, I am doing a form submission using jquery:
......submit(function(){
validate=false;
formInfo = validateForm(validate,$thisLi);
if(formInfo.validate){
**fillClaimForm.submit();**
}
return false;
});
It is working on all browsers except IE8
Can someone kindly help me.
Thanks
Close your form.
Also give the same name as the id for your form and use
$("#formId").submit();
Code
<form class="fillClaimForm" name="fillClaimForm" method="POST" enctype="multipart/form-data" action="<?php print BASE_URL; ?>?action=insertBlogger" >
<label for="fblogName">Blog's name: </label>
<input type="text" name="fblogName" id="fblogName" class="cfInput" placeholder ="Complex" required />
<label for="fblogUrl">URL: </label>
<input type="text" name="fblogUrl" id="fblogUrl" class="cfInput" placeholder ="www.complex.com" required />
<label>Blog's logo: </label>
<div class="upload-file-container"><span>UPLOAD</span>
<input type="file" name="fblogLogo" id="fblogLogo"/>
<p class="ErrLoad error" style="display:none;">Please load your logo</p>
</div>
<label for="fEmail">Email adresse: </label>
<input type="email" name="fEmail" id="fEmail" class="cfInput" required />
<label for="frNum">Phone number: </label>
<input type="tel" name="frNum" id="frNum" class="cfInput" required />
<input type="hidden" name="idVid" id ="idVid" value=""/>
<input type="hidden" name="idRubrique" id ="idRubrique" value=""/>
<button id="sendClaim" class="sendClaim">SEND</button>
</form>
$("#sendClaim").click(function(){
validate=false;
formInfo = validateForm(validate,$thisLi);
if(formInfo.validate){
$("#fillClaimForm").submit();
}
return false;
});
Try this:
document.forms.fillClaimForm.submit();
Or if the ...... in your code represents creating of a submit handler on that same form you can probably just say this.submit().

How to process multiple forms using one php script

I have multiple forms and I have one php script that I want to use to process these forms but when I click on submit for any of the forms...the script is processed by the number of forms with the submit button named 'submitForm' in this case, the alert will show 3 times instead of once! What am I not doing right?
NB. I hope this makes much sense?
html code
<form action="" name="form1" method="post">
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<form action="" name="form2" method="post">
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<form action="" name="form3" method="post">
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
php script
<?php
if (isset($_POST['submitForm'])) {
echo('<script>alert("Form Submitted")</script>');
}
?>
when I click on submit for any particular form, it submits all the forms.
this is not true.
Once your forms have proper formatting, your browser will submit only current one.
(and PHP has nothing to do here)
however, whole page will be reloaded, if you mean that. That is okay - when you submit a form, a page is intended to reload. If you need another behavior, you have to explain your wishes.
Also note that none of your text fields being sent to the server as they have no names.
I guess the question I should be asking is, how do I pass a particular form to php instead of writing multiple php scripts to handle each form!!!
well, it seems you want to ask how to distinguish these forms.
add a hidden field into each
<input type="hidden" name="step" value="1" />
and then in PHP
if ($_POST['step'] == 1) {
//first form
}
if ($_POST['step'] == 2) {
//second
}
This submits one form of many to php. Copy, paste, test, and study.
<?php
if (isset($_POST['submitForm'])) {
print_r($_POST);
}
?>
<form action="" name="form1" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<form action="" name="form2" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<form action="" name="form3" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
Using a,b,c,d for the first form, e,f,g,h for the second form and i,j,k,l for the third form and submitting the second form yields the following output:
Array
(
[A] => e
[B] => f
[C] => g
[D] => h
[submitForm] => Submit Form
)
#Jay
Actually its not hard.
Once you supply form names, your work is done. the DOM does the rest.
write one php block to do your functions (create/update/retrieve/delete)
Whichever button is clicked, by default it submits only the elements enclosed together with it.
if(!empty($_POST)){
if(isset($_POST['submit'])){
print "<pre>";
var_dump($_POST); // write your code here as you would
print "<pre>";
}
}
try this with your form above.
I know this is an old post but here's how I solve this very problem.
All you need to do is make sure the submit buttons in each form have different names. Eg:
<form action="" name="form1" method="post">
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="Submit" value="Submit Form" name="submitForm1" />
</form>
<form action="" name="form2" method="post">
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="Submit" value="Submit Form" name="submitForm2" />
</form>
<form action="" name="form3" method="post">
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="Submit" value="Submit Form" name="submitForm3" />
</form>
Then, you simply check which form's submit button was pressed.
<?php
if (isset($_POST['submitForm1'])) {
echo('<script>alert("Form 1 Submitted")</script>');
} elseif (isset($_POST['submitForm2'])) {
echo('<script>alert("Form 2 Submitted")</script>');
} elseif (isset($_POST['submitForm3'])) {
echo('<script>alert("Form 3 Submitted")</script>');
}
?>
If you need dynamic forms, you may try below code. While statement can be changed to fetch data from DB and use foreach instead. Hope you know this.
Here, I used while($n<10) for 10 dynamic forms.
You can also use tag as below if you need separate form names.
<form action="" name="form<?=$n?>" method="post">
This will create separate form names such as form1, form2, etc but not necessary here.
<?php
if (isset($_POST['submitForm'])) {
echo '<pre>';
print_r($_POST);
echo '</pre>';
}
$n=0;
while($n<10) {
$n++;
?>
<form action="" name="form1" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<?php
}
?>
Sample page with output when I click row 5..

Categories