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
calling mail() from a button / link
Moderator: General Moderators
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");
?>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...
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...