Jump to content

Can not send the email TO someone.


evlj

Recommended Posts

Hi guys, i have a custom made php that collect all the info in admin page (long story short), there's a button called "Approve" I would like to send back an email to user who applied with picture, once Approved button is pressed, so here's the script:

 

<?php
session_start();
$user = '123';
$pass = '123';
$to = $data['email'];
$subject = 'blablabla';
$message = 'test123';
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_USER'] != $user || $_SERVER['PHP_AUTH_PW'] != $pass)
{
    header('WWW-Authenticate: Basic realm="Enter password to access this page."');
    header('HTTP/1.0 401 Unauthorized');
    echo"You must be logged in to see this page.";
    exit;
}
################## PROTECTED CONTENT ########################
require('./config.php');
?>
<!DOCTYPE HTML>
<html>
    <head>
        <title>ADMIN PANEL</title>
        <style type="text/css">
            body{width: 960px; margin: auto; margin-top: 20px; padding: 5px 20px; box-shadow: 0px 0px 2px #000000; border-radius: 5px;background:transparent url(images/bg_header.gif) top left repeat-x;}
            a:link,a:active,a:visited{color: inherit; text-decoration: none;}
            a:hover{text-decoration: underline;}
            .button{background:transparent url(images/grad.PNG) bottom left repeat-x; padding: 3px 5px; border-radius: 4px; border: 1px solid #cccccc;}
            .button:hover{border-color:orangered;text-decoration:none;}
            .approve .img{max-height: 200px; max-width: 200px; position: absolute; right: 5px; top: 5px;}
            .approve{display: block; height: 200px; overflow: hidden; box-shadow: 0px 0px 2px #000000; margin-top: 20px; padding: 20px; position: relative; font:13px verdana;}
            textarea,input{padding: 3px;font: 13px helvetica,verdana;border:1px solid rgb(51,151,251);border-radius: 4px;width: 300px; display: block;
                           margin: 5px 0px;}
            input:hover,textarea:hover{border-color:orangered;cursor:pointer;}
            form{font:bold 13px verdana;}
            input[type='submit'],input[type='button']{width: auto;}
        </style>
    </head>
    <body>
        <?php
        echo"
<div id='head'>
<h1 align='center'>ADMIN PANEL</h1>
    <h4 align='center'><a href='index.php' class='button'>Homepage</a> <a  class='button' href='admin.php'>Approval Queue</a> <a class='button' href='admin.php?edit'>Edit Image info.</a> <a class='button' href='?edit&view'>View Image Info.</a></h4>
</div>";
        if (isset($_GET['edit']))
        {
            if (isset($_GET['pid']))
            {
                $pic = mysql_query('SELECT * from `' . $table_name . '` WHERE pid = ' . intval($_GET['pid']));
                if (mysql_num_rows($pic) == 1)
                {
                    if (isset($_POST['submit']))
                    {
                        $approved = isset($_POST['approved']) && $_POST['approved'] == '1' ? 1 : 0;
                        mysql_query('UPDATE `' . $table_name . '` SET ' .
                                        'first_name = "' . $_POST['first'] . '",' .
                                        'last_name="' . $_POST['last'] . '",' .
                                        'phone="' . $_POST['phone'] . '",' .
                                        'email="' . $_POST['email'] . '",' .
                                        'first_name="' . $_POST['first'] . '",' .
                                        'approved=' . $approved . ',' .
                                        'address="' . $_POST['addr'] . '",' .
                                        'admin_desc="' . $_POST['admin_desc'] . '"' .
                                        ' WHERE pid = ' . intval($_GET['pid'])) or exit("Unable to edit" . mysql_error());
                        echo'<h3>EDITED</h3>';
                        $pic = mysql_query('SELECT * from `' . $table_name . '` WHERE pid = ' . intval($_GET['pid']));
                    }
                    $data = mysql_fetch_array($pic);
                    if (isset($_GET['view']))
                    {
                        echo'
                <strong>Uploaded by </strong>' . $data['first_name'] . ' ' . $data['last_name'] . '
                <br />
                <img src="' . $default_dir . $data['image_name'] . '" style="max-width: 200px; max-height:200px; float: right;" />
                    <br />
                    <br />
	<b>First_name :</b> ' . $data['first_name'] . '
                    <br />
                    <br />
                <b>Last_name :</b> ' . $data['last_name'] . '
                    <br />
                    <br />
                <b>Phone :</b> ' . $data['phone'] . '
                    <br />
                    <br />
                <b>Email :</b> ' . $data['email'] . '
                    <br />
                    <br />
                <b>Approved :</b> ' . ($data['approved'] == 1 ? 'Yes' : 'No') . '
                    <br />
                    <br />
                <b>Address :</b> ' . $data['address'] . '
                    <br />
                    <br />
                <b>Admin_description :</b> 
                                    <br />
                    <br />' . $data['admin_desc'] . '
                    <br />
                    <br />
                    <a href="?edit&pid=' . $data['pid'] . '" class="button">Edit</a>
                                            <br />
                    <br />
';
                    }
                    else
                    {
                        echo'<form method="POST" action="?edit&pid=' . intval($_GET['pid']) . '">
                Editting photo: <a style="color:rgb(51,151,251);" href="' . $default_dir . $data['image_name'] . '">' . $data['image_name'] . '</a> uploaded by ' . $data['first_name'] . ' ' . $data['last_name'] . '
                <br />
                <img src="' . $default_dir . $data['image_name'] . '" style="max-width: 200px; max-height:200px; float: right;" />
                    <br />
			First_name : <input type="text" name="first" value="' . $data['first_name'] . '" />
                Last_name : <input type="text" name="last" value="' . $data['last_name'] . '" />
                Phone : <input type="text" name="phone" value="' . $data['phone'] . '" />
                Email : <input type="text" name="email" value="' . $data['email'] . '" />
                Approved : <input type="text" name="approved" value="' . $data['approved'] . '" /> 0 or 1
                Address : <textarea name="addr">' . $data['address'] . '</textarea>
                Admin_description : <textarea name="admin_desc">' . $data['admin_desc'] . '</textarea>
                <input type="submit" name="submit" value="Edit" />
                </form>';
                    }
                }
                else
                {
                    echo"NO SUCH PICTURE EXISTS";
                }
            }
            else
            {
                echo"
            <h3>Search for image to " . (isset($_GET['view']) ? 'view' : 'edit') . " it: </h3>
            <form id='form' method='POST' action='admin.php?edit" . (isset($_GET['view']) ? '&view' : '') . "'>
            Uploader's first name: <input type='text' name='name' value='' /> OR 
            Image name: <input type='text' name='img' value='' /> OR 
            Email: <input type='text' name='email' value='' />
             <input type='submit' name='submit' value='Search' />
            </form>";
                if (isset($_POST['submit']))
                {
                    $name = empty($_POST['name']) ? '%' : '%' . $_POST['name'] . '%';
                    $email = empty($_POST['email']) ? '%' : '%' . $_POST['email'] . '%';
                    $img = empty($_POST['img']) ? '%' : '%' . $_POST['img'] . '%';
                    $query = mysql_query(
                            'SELECT * from `' . $table_name . '` where ' .
                            'first_name like "' . $name . '" and ' .
                            'email like "' . $email . '" and ' .
                            'image_name like "' . $img . '"');
                    if (mysql_num_rows($query) > 0)
                    {
                        while ($pic = mysql_fetch_array($query))
                        {
                            echo"<hr/><strong>Uploaded by $pic[first_name] $pic[last_name] " . date(' \a\t H:i \o\n d/m/Y', intval($pic['image_name'])) .
                            "</strong> - <a href='$default_dir$pic[image_name]' target='_blank'>$pic[image_name]</a>
                              <a href='?edit" . (isset($_GET['view']) ? '&view' : '') . "&pid=$pic[pid]' class='button'>" . (isset($_GET['view']) ? 'View' : 'Edit') . "</a>";
                        }
                    }
                    else
                    {
                        echo "NO IMAGE MATCHES THAT DESCRIPTION";
                    }
                }
            }
            exit;
        }
        if (isset($_GET['approve']))
        {
            if (mysql_query('UPDATE `' . $table_name . '` SET approved = 1 WHERE pid = ' . intval($_GET['approve'])))
            {
        if (@mail($to, $subject, $message)) { echo('<p>Mail sent successfully.</p>'); } else { echo('<p>Mail could not be sent.</p>'); }
	echo"<h2>APPROVEDs</h2>";
            }
        }

 

 

It's not whole script though.

Link to comment
https://forums.phpfreaks.com/topic/257258-can-not-send-the-email-to-someone/
Share on other sites

I would like to know how can i send the email back to uploader of an image once the button "Approve" is pressed. It's here:

 

        if (@mail($to, $subject, $message)) { echo('<p>Mail sent successfully.</p>'); } else { echo('<p>Mail could not be sent.</p>'); }

echo"<h2>APPROVEDs</h2>";

            }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.