Page 1 of 1
PHP linked to button
Posted: Wed Nov 24, 2010 10:35 am
by Chronix
Hi, im completely new to PHP and I am trying to link a button to a PHP so that it will send an email to the specific one in the PHP and was wondering if anyone knows how I will be able to link these.
BTW: New here, hope my first post is correct

Re: PHP linked to button
Posted: Wed Nov 24, 2010 12:00 pm
by califdon
Welcome to the forum and to PHP. Let me restate what I think you are asking: How can I run a PHP script by clicking on a button on an HTML page? The answer is that you can either enclose the button in a hyperlink, like this:
Code: Select all
<a href="http://mysite.com/myscript.php">
<input type='button' value='Click Here' /></a>
or by using Javascript, like this:
Code: Select all
<input type='button' value='Click Here' onClick='document.location="mysite.com/myscript.php";' />
or by using an HTML form, like this:
Code: Select all
<form name='xxx' method='post' action='myscript.php'>
Enter your name here: <input type='text' name='myname' /><br />
<input type='submit' value='Click Here to Submit' /></form>
Read some PHP tutorials.
Re: PHP linked to button
Posted: Thu Nov 25, 2010 1:42 am
by tutigan
If you want to send an email to someone using PHP, have a look at the mail function:
http://php.net/manual/en/function.mail.php
You can set up a little form to send emails to someone as well, have a look at this:
Code: Select all
<?php
//this checks whether the form has been submitted
if(!$_POST['submit']) {
//it hasnt, so display the form
echo "<form method='post' action=''>
Please enter the email address you wish to send to:<br />
<input type='text' name='email' /><br />
Please enter the subject for the email:<br />
<input type='text' name='subject' /><br />
Please enter the body of the email:<br />
<textarea name='body' rows='5' cols='25'></textarea>
<input type='submit' name='submit' value='submit' />
</form>";
} else {
//form has been submitted
//collect inputs, send email
$to = $_POST['email'];
$subject = $_POST['subject'];
$body = $_POST['body'];
mail = ($to, $subject, $body);
echo "Email to " . $to . " has been sent!";
}
?>
you can also change who it comes from and more using headers, but this is just basic!
Re: PHP linked to button
Posted: Thu Nov 25, 2010 3:16 am
by Chronix
Hi again, ive got the button working to send me an email whenever I click submit.
Now what I have to do is figure out how to add different variables(?) to the php so that when you click submit, it sends all the data to the email and not just the email address and the subject.
Heres the code im using at the moment, can you tell me where ive gone wrong?
Code: Select all
<?php
$email = $_GET['Email'] ;
$message = $_GET['Test1 . Test2 . Test3 . Test4 . Test5'] ;
mail( "test1049@live.co.uk", "Test PHP",
$message, "From: $email" );
?>
Re: PHP linked to button
Posted: Thu Nov 25, 2010 10:54 am
by Chronix
Can anyone help me? I really need to know this
Re: PHP linked to button
Posted: Thu Nov 25, 2010 12:33 pm
by califdon
Code: Select all
$message = $_GET['Test1'] . $_GET['Test2'] . $_GET['Test3'] . $_GET['Test4'] . $_GET['Test4'] ;