Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Yay
    Yay is offline
    Regular Coder Yay's Avatar
    Join Date
    Oct 2008
    Location
    54° North, 1° West
    Posts
    102
    Thanks
    9
    Thanked 1 Time in 1 Post

    Exclamation Passing the variable for an e-mail address through the URL for use with PHP mail.

    Hi there,

    I've came across a problem. My mail script works fine, just that I need to know how to get the value for an e-mail from the URL (passed on via a different page). Here's my code so far for both pages. Certsend is the one which does the main mail work. Basically, I'd like the value of $to to be what the value of mail is in the URL.

    Certsend
    PHP Code:
    <?php

        $to 
    'yourmail@k.com';
        
    $subject 'You have receieved a certificate from the Pyongyang Pair!'
        
    $from 'Pyongyang Pair';
        
    $name $_GET['name'];


        
    //begin of HTML message 
        
    $message '<!DOCTYPE html>
    <html>
    <head>
        <title>Pyongyang Pair Certificate</title>
        
        <!-- CSS -->
        
        <style type="text/css">
        body{
            text-align: center;
        }
        
        #cert{
            width: 1648px;
            height: 821px;
            margin: 0 auto;
            background: url(\'http://kwivia.co.uk/images/certjpg.jpg\');
            margin-left: -10px;
            margin-top: -10px;
            margin-bottom: -10px;
        }
        
        #input{
            padding-top: 40em;
            float: left;
            padding-left: 9em;
        }
        .input{
            width: 900px;
            height: 80px;
            background: none;
            font-family: georgia;
            color: #fff;
            font-size: 50px;
            text-align: center;
            border: 0;
        }
        </style>
    </head>
    <body>

    <div id="cert">

    <div id="input">
    $name
    </div>

    </div>

    '
    ;
    ?>

    <?php 
    $headers  
    'MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1';


    if(
    mail($to$subject$message"$headers From: $from")){
      echo 
    "Mail sent";
    }else{
      echo 
    "Mail send failure - message not sent";  }
    ?>
    Home.php
    PHP Code:
      <?php 


    $db 
    ='pp';

    require(
    "connect.php"); 


    // select db
    mysql_select_db($db) or die ("Unable to select database!"); 

    // pagination of sql results
    // find number of rows in table
    $sql"SELECT COUNT(*) FROM members";
    $result mysql_query($sql$con) or trigger_error("SQL"E_USER_ERROR);
    $r mysql_fetch_row($result);
    $numrows $r[0];

    //number of rows per page
    $rowsperpage 3;
    // find out total pages
    $totalpages ceil($numrows $rowsperpage);

    // get the current page or set a default
    if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
       
    // cast var as int
       
    $currentpage = (int) $_GET['currentpage'];
    } else {
       
    // default page num
       
    $currentpage 1;
    // end if

    // if current page is greater than total pages...
    if ($currentpage $totalpages) {
       
    // set current page to last page
       
    $currentpage $totalpages;
    // end if
    // if current page is less than first page...
    if ($currentpage 1) {
       
    // set current page to first page
       
    $currentpage 1;
    // end if

    // the offset of the list, based on current page 
    $offset = ($currentpage 1) * $rowsperpage;


    // query
    $query "SELECT
     members.Name
     , members.Member_ID
     , members.dob
     , members.Mail
     , COUNT(gigs.name_of_gig) AS gig_count
    FROM members AS members
    LEFT JOIN gigs AS gigs
      ON members.Member_ID=gigs.member_id 
    GROUP BY  members.Name, members.Member_ID, members.dob, members.Mail
    ORDER BY Member_ID DESC LIMIT $offset, $rowsperpage"
    ;



    // execute query 
    $result mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 


    // return rows check
    if (mysql_num_rows($result) > 0) { 
        
    // yes 
        // print rows
        
    echo "<table cellpadding=10 border=0><strong><td><strong>Name</strong></td><td><strong>Gigs Attended</strong></td><td><strong>Date of Birth</strong></td><td><strong>Email</strong></td><td><strong>Add new Gig</strong></td><td><strong>Send Certificate</strong>"
     
     while(
    $row mysql_fetch_array($result)){
           echo 
    "<tr>"
           echo 
    "<td>".$row['Name']."</td>"
           echo 
    "<td>".$row['gig_count']."</td>"
           echo 
    "<td>" .$row['dob']."</td>"
           echo 
    "<td>".$row['Mail']."</td>"
           echo 
    "<td><a href=\"/records/add_gigs.php?id=".$row['Member_ID']."&?name=".$row['Name']."\"><button class=\"submit\">Add new Gig</button></a></td>";
             if(
    $row['gig_count']> 2) {
    echo 
    "<td><a href=\"/certsend.php?name=".$row['Name']."&?Mail=".$row['Mail']."\"><button class=\"submit\">Make Certificate!</button></a></td>"


    }              echo 
    "</tr>";
        } 
        echo 
    "</table>"

    else { 
        
    // if no 
        // print message
        
    echo "no data found"



    // range of num links to show
    $range 3;

    echo 
    "<span class=\"pag\"><p style=\"font-size: 16px;\" align=\"center\">Page ";

    // loop to show links to range of pages around current page
    for ($x = ($currentpage $range); $x < (($currentpage $range) + 1); $x++) {
       
    // if it's a valid page number...
       
    if (($x 0) && ($x <= $totalpages)) {
          
    // if we're on current page...
          
    if ($x == $currentpage) {
             
    // 'highlight' it but don't make a link
             
    echo "<button class=\"pagination\" style=\"font-size: 15px; font-weight: bold;'\">&nbsp;$x&nbsp;</button>";
          
    // if not current page...
          
    } else {
             
    // make it a link
             
    echo "&nbsp;<button class=\"pagination\" style=\"font-size: 15px;'\"><a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a></button>";
          } 
    // end else
       
    // end if 
    // end for
                     

    echo "&nbsp;out of $totalpages</h2></span>";

    // free result set memory 
    mysql_free_result($result); 

    // close connection 
    mysql_close($con); 

    ?>
    Anything else, ask!
    Thanks,
    Jack
    Words and phrases to use when you pretend to know something on CodingForums: Yes. Indeed. Well done. Absolutely Great. Top-notch. Awesome. Cool. Very Good. I see. Oh, yes. I understand. Good.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    $to would simply become $_GET['Mail'].
    You'll want to validate it though to ensure that its at least just an email address. Look into the filter_var() to see the validation filter for emails. Works not too bad, the filter is FILTER_SANITIZE_EMAIL and FILTER_VALIDATE_EMAIL.

    Edit:
    Hmm, wait a minute. Can you even wrap a button element with an anchor element?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    Yay (02-22-2010)

  • #3
    Yay
    Yay is offline
    Regular Coder Yay's Avatar
    Join Date
    Oct 2008
    Location
    54° North, 1° West
    Posts
    102
    Thanks
    9
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Fou-Lu View Post
    $to would simply become $_GET['Mail'].
    You'll want to validate it though to ensure that its at least just an email address. Look into the filter_var() to see the validation filter for emails. Works not too bad, the filter is FILTER_SANITIZE_EMAIL and FILTER_VALIDATE_EMAIL.

    Edit:
    Hmm, wait a minute. Can you even wrap a button element with an anchor element?
    I'll look into the aforementioned function, and I the button seems to work fine with the anchor attached to it—sends me to the correct page.
    Words and phrases to use when you pretend to know something on CodingForums: Yes. Indeed. Well done. Absolutely Great. Top-notch. Awesome. Cool. Very Good. I see. Oh, yes. I understand. Good.

  • #4
    Yay
    Yay is offline
    Regular Coder Yay's Avatar
    Join Date
    Oct 2008
    Location
    54° North, 1° West
    Posts
    102
    Thanks
    9
    Thanked 1 Time in 1 Post
    Sorry for the double post:

    When I try
    $to = $_GET['Mail'];
    $subject = 'You have receieved a certificate from the Pyongyang Pair!';
    $from = 'Pyongyang Pair';
    $name = $_GET['name'];


    I get a PHP error which relates to the line with $to on it, saying that there's an undefined index. Is there something I'm missing in home.php?
    Words and phrases to use when you pretend to know something on CodingForums: Yes. Indeed. Well done. Absolutely Great. Top-notch. Awesome. Cool. Very Good. I see. Oh, yes. I understand. Good.

  • #5
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Get rid of the ? preceding Mail on this line:

    Code:
    echo "<td><a href=\"/certsend.php?name=".$row['Name']."&?Mail=".$row['Mail']."\"><button class=\"submit\">Make Certificate!</button></a></td>";

  • Users who have thanked MattF for this post:

    Yay (02-22-2010)

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by MattF View Post
    Get rid of the ? preceding Mail on this line:

    Code:
    echo "<td><a href=\"/certsend.php?name=".$row['Name']."&?Mail=".$row['Mail']."\"><button class=\"submit\">Make Certificate!</button></a></td>";
    Hah, yeah that will do it. Too much vb methinks O.o
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •