calling mail() from a button / link

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mrdave
Forum Newbie
Posts: 2
Joined: Sun May 29, 2005 2:04 pm

calling mail() from a button / link

Post 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
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Just examples...

Code: Select all

<a href=&quote;mailto.php?userid=123&quote;>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");
?>
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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...
mrdave
Forum Newbie
Posts: 2
Joined: Sun May 29, 2005 2:04 pm

Post 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?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Post Reply