Page 1 of 1
calling mail() from a button / link
Posted: Sun May 29, 2005 2:08 pm
by mrdave
Hi
i have created my php code mail() function but would like to invoke this when i press a link or press a button.
Im using it to send reminder emails to customers and only want them to be sent when i click on the link from an admin area.
anyone any examples i could try.
thanks v m
Posted: Sun May 29, 2005 2:23 pm
by JAM
Just examples...
Code: Select all
<a href="e;mailto.php?userid=123"e;>Mail Customer</a>
Code: Select all
<?php
// mailto.php
// include your database layer/connection
require 'db_connection.php';
// fetch the email info
$email = $db->query("select email from customers where id = $_GET[userid]");
// do the mailing
mail($email, "Subject", "Message", $headers_of_choise);
// forward yourself to a page of choise
header("Location: ./somepage.php");
?>
Posted: Sun May 29, 2005 3:09 pm
by Burrito
because php is server side, you're going to have to submit a page to the server in order to send an email.
you could make it appear it's on the same page however if you use a hidden frame of some kind (iframe perhaps), or you could do it with a pop up window that auto closes etc... but bottom line, in order to "invoke" your function, you're going to have to send something to the server.
JAM's code should work for you...
Posted: Sun May 29, 2005 5:15 pm
by mrdave
thanks v m for this
will give this a go.
are there any good online guides with examples on for various mail functions?
Posted: Sun May 29, 2005 9:47 pm
by JAM