BTW: New here, hope my first post is correct
PHP linked to button
Moderator: General Moderators
PHP linked to button
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
BTW: New here, hope my first post is correct
Re: PHP linked to button
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:or by using Javascript, like this:or by using an HTML form, like this:
Read some PHP tutorials.
Code: Select all
<a href="http://mysite.com/myscript.php">
<input type='button' value='Click Here' /></a>Code: Select all
<input type='button' value='Click Here' onClick='document.location="mysite.com/myscript.php";' />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>Re: PHP linked to button
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:
you can also change who it comes from and more using headers, but this is just basic!
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!";
}
?>
Re: PHP linked to button
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?
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
Can anyone help me? I really need to know this
Re: PHP linked to button
Code: Select all
$message = $_GET['Test1'] . $_GET['Test2'] . $_GET['Test3'] . $_GET['Test4'] . $_GET['Test4'] ;