1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

mail system with php. how to?

Discussion in 'PHP & Perl' started by SpiderWebMaster, Feb 20, 2010.

  1. SpiderWebMaster

    SpiderWebMaster Power Member

    Joined:
    Jan 24, 2009
    Messages:
    617
    Likes Received:
    519
    Occupation:
    I don't have a job...
    Location:
    /dev/null
    well, i've searched around google and i can't seem to find what i need, wich is more simple than a mail form.

    i have a tv show site and would like to put a Report link at the bottom of the posts that would mail me the URL of the post, so i know the link is dead and replace it.

    i know it's nothing fancy. it wouldn't even need another page to open, just ppl to press the Report link and it would silently send me the mail containing the link of the page where it was pressed. maybe echoing one line saying report sent or something only.

    If somebody can help me with this i'm willing to contribute to your paypal account! :D
     
  2. n2zen

    n2zen Regular Member

    Joined:
    Sep 27, 2009
    Messages:
    269
    Likes Received:
    70
    Some might say this is overkill, but I like it. Below is the code for 2 files, contact.php and contact.html which together make an Ajax link reporter. Read em over, tweak your email address in the php file, and not much else needs done.

    You'll just want to cut and paste the html into whatever page/template you need it in.

    This is code based on the Ajax Contact Form by Andrew Walsh.

    I've tested this and it does work :) It autodetects the URL the user is on and then when they click the Report Link button, it emails you and changes the message to 'Link Reported', all without having to refresh the page or send them to a thank you page...

    contact.html
    Code:
    <html>
    <head>
    <title>Based on Ajax Contact Form by Andrew Walsh</title>
    <style type="text/css">
    body {text-align:center;	}
    	
    #contactarea {
    	width:100px;
    	margin:0px auto;
    	text-align:left;
    	font-weight: bold;
    	font-family: Verdana, Arial;
    	font-size: 12px;
    }
    
    #submitbutton {
    	border: 1px solid #000;
    	background-color: #eee;
    
    }
    </style>
    
    <script language="javascript">
    
    function createRequestObject() {
        var ro;
        var browser = navigator.appName;
        if(browser == "Microsoft Internet Explorer"){
            ro = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
            ro = new XMLHttpRequest();
        }
        return ro;
    }
    
    var http = createRequestObject();
    
    function sendemail() {
    	var msg = document.location.href;
    	var name = 'Link Monitor';
    	var email = 'system@yourmonitor.com';
    	var subject = 'Link Down';
    	document.contactform.send.disabled=true; 
    	document.contactform.send.value='Sending....';
    
        http.open('get', 'contact.php?msg='+msg+'&name='+name+'&subject='+subject+'&email='+email+'&action=send');
        http.onreadystatechange = handleResponse;
        http.send(null);
    }
    
    function handleResponse() {
        if(http.readyState == 4){
            var response = http.responseText;
            var update = new Array();
    
            if(response.indexOf('|' != -1)) {
                update = response.split('|');
                document.getElementById(update[0]).innerHTML = update[1];
             
            }
        }
    }
    </script>
    </head>
    <body>
    <div id="contactarea"><form name="contactform" id="contactform"><input type="button" value="Report Link" name="send" onClick="sendemail();" id="submitbutton"></form></div>
    </body>
    </html>
    

    contact.php
    Code:
    <?php
    /*
    
    Author: Andrew Walsh
    Date: 30/05/2006
    Codewalkers_Username: Andrew
    
    
    This script is a basic contact form which uses AJAX to pass the information to php, thus making the page appear to work without any refreshing or page loading time.
    
    */
    
    $to = "your@emailaddress.com"; //This is the email address you want to send the email to
    $subject_prefix = ""; //Use this if you want to have a prefix before the subject
    
    if(!isset($_GET['action']))
    {
    die("You must not access this page directly!"); //Just to stop people from visiting contact.php normally
    }
    
    /* Now lets trim up the input before sending it */
    
    $name = trim($_GET['name']); //The senders name
    $email = trim($_GET['email']); //The senders email address
    $subject = trim($_GET['subject']); //The senders subject
    $message = trim($_GET['msg']); //The senders message
    
    mail($to,$subject,$message,"From: ".$email.""); //a very simple send
    
    echo 'contactarea|Link Reported!'; //now lets update the "contactarea" div on the contact.html page. The contactarea| tell's the javascript which div to update.
    ?>
    
     
    • Thanks Thanks x 1
  3. SpiderWebMaster

    SpiderWebMaster Power Member

    Joined:
    Jan 24, 2009
    Messages:
    617
    Likes Received:
    519
    Occupation:
    I don't have a job...
    Location:
    /dev/null
    holy shit man. this is exactly what i wanted! i was afraid of sounding confusing but it seems you understood exactly what i wanted to say.

    Now, what can i do for you besides thanking you a lot?

    Thanks Thanks Thanks!
     
  4. n2zen

    n2zen Regular Member

    Joined:
    Sep 27, 2009
    Messages:
    269
    Likes Received:
    70
    No need for anything more than a thanks. I'm just happy to return the favour (for all those good GET threads you start), and to hear that it's going to work out for you :)

    I'm not a guru, but if you ever need a hand with anything php/mysql, gimme a shout.
     
    • Thanks Thanks x 1
  5. SpiderWebMaster

    SpiderWebMaster Power Member

    Joined:
    Jan 24, 2009
    Messages:
    617
    Likes Received:
    519
    Occupation:
    I don't have a job...
    Location:
    /dev/null
    well, it works perfectly man! really! i understand very little of php/mysql, just enough to fix some little problems that i face sometimes, i couldn't ever code any script from scratch, so you gave me a good help here. I really searched i dunno how many pages with contact forms and php tutorials without finding what i needed, so i asked here and you we're kind enough to help me! PM me if you want to see it in action. i'll send you the URL.

    thanks again for this!