www.webdeveloper.com
Results 1 to 4 of 4

Thread: Need Help With PHP

Hybrid View

  1. #1
    Join Date
    Apr 2012
    Posts
    3

    Need Help With PHP

    Hi Everyone,

    I am very new to PHP, and I need some help with a project I am working on. So basically what happens is the QR code is generated and a short URL is generated as well for the QR Code, and what I need is the short URL that is generated to be sent to my email address. Here is what the code looks like:
    PHP Code:
    <?php

    class Url_shortner_class {
        
        function 
    shorten_url($criteria=array()) {
            
    $url $criteria['url'];
            
    $type $criteria['type']; //google
            
            
    if($type=='google') {
                return 
    $this->shorten_url_with_google(array('url'=>$url));
            }
        }
        
        
    /*
        Google shortner service
        */
        
    function shorten_url_with_google($criteria=array()) {
            
    $url $criteria['url'];
            
            
    $api_url 'https://www.googleapis.com/urlshortener/v1/url';
            if(
    $GLOBALS['google_api_key']!=''$api_url .= '?key='.$GLOBALS['google_api_key'];
            
            
    $result getDataFromUrl($api_urljson_encode(array("longUrl"=>$url)), 'json');
            
    $result json_decode($result,true);
            
            
    $data['longUrl'] = $url;
            
    $data['shortUrl'] = $result['id'];
            
            return 
    $data;
        }
        
    }

    ?>
    All I need is to add a section that will send the URL to my email address, but I am unsure on how to write the code to do that. Thank you!

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,152
    You can use PHP's mail() function, or you could look into using something like PHPMailer to deal with a lot of the details.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Apr 2012
    Posts
    3
    So if I were to use the mail function would it look like this?

    PHP Code:
    $data['longUrl'] = $url
            
    $data['shortUrl'] = $result['id']; 
    then add...

    PHP Code:
    mail("somebody@example.com","My subject",$url); 
    Thank you!

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,152
    Depending on your server config, you might have to add some additional mail headers in the 4th (optional) parameter.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles