Jump to content

Variables Missing in mail function


NICON

Recommended Posts

Quite simple my mail is failing to send. The $_POST variable is not echo ing after being reassigned to $message and $email is not appearing either to satisfy the mail() function. I know i'

<?php
require_once __DIR__ . '/header.php';
require_once __DIR__ . '/includes/class_mtg_paginate.php';
$opts = ['grpgusers', 'gdemails'];
$names = ['MS', 'GD'];
$view = isset($_GET['view']) && in_array($_GET['view'], $opts) ? $_GET['view'] : 'grpgusers';

if (!$user_class->admin)
    $mtg->error("You don't have access");
if (array_key_exists('ms', $_POST)) {
    $db->query("SELECT id, email FROM grpgusers ORDER BY id ASC LIMIT 2");
    $db->execute();
    $rows = $db->fetch_row();
    $success = 0;
    $failure = 0;
    echo 'Sending...<br />';
    $message = stripslashes($_POST['message']);
	$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
	foreach ($rows as $row) {
        $email = $row['email'];
        if (mail("$email", "A message from MS", "$message", "$headers"))
            ++$success;
        else
            ++$failure;
    }
$mtg->success("Message sent to " . $mtg->format($success) . " user" . $mtg->s($success) . ". Failed to send to " . $mtg->format($failure) . " user" . $mtg->s($failure));
}
if (array_key_exists('gd', $_POST)) {
    $db->query("SELECT id, email FROM gdemails ORDER BY id ASC LIMIT 2");
    $db->execute();
    $rows = $db->fetch_row();
    $success = 0;
    $failure = 0;
    echo 'Sending...<br />';
    $message = stripslashes($_POST['message']);
    foreach ($rows as $row) {
        $email = $row['email'];
        if (mail("$email", "A message from MS", "$message"))
            ++$success;
        else
            ++$failure;
    }
    $mtg->success("Message sent to " . $mtg->format($success) . " user" . $mtg->s($success) . ". Failed to send to " . $mtg->format($failure) . " user" . $mtg->s($failure));
}
$pages = new Paginator();
if($_GET['view'] == "grpgusers") {
	$db->query("SELECT COUNT(id) FROM grpgusers");
	$submit = "ms";
} else {
	$db->query("SELECT COUNT(id) FROM gdemails");
	$submit = "gd";
}
$db->execute();
$pages->items_total = $db->fetch_single();
$pages->mid_range = 5;
$pages->paginate();
?>
<tr><th class='contenthead'>Mass Email</th></tr>
<tr><td class='contentcontent'>
<form action='staff_mail.php' method='post'>
	<table id='mttable' width='100%'>
		<tr>
			<th width='25%'>Message</th>
			<td width='75%'><textarea name='message' rows='10' cols='60'></textarea></td>
		</tr>
		<tr>
			<td colspan='2' class='center'><input type='submit' name='<?php echo $submit; ?>' value='Send Email' /></td>
		</tr>
	</table>
</form>
<br />
        <div class='paginate'><?php echo $pages->display_pages(); ?></div>
		<br />
		<form action="staff_mail.php" method="get">
            <table width="100%" id='mttable'>
                <tr>
                    <th width='25%'>Emailer List</th>
                    <td width='75%'><select name='view' onchange='this.form.submit()'>
                            <option value='grpgusers'>Select...</option>
                            <?php
                            $c = 0;
                            foreach ($opts as $opt) {
                                printf("<option value='%s'>%s</option>", $opt, $names[$c]);
                                $c++;
                            }
                            ?></select></td>
                </tr>
            </table>
        </form>
		<br />
		<table id='mttable' width='100%'>
			<tr>
				<td colspan='5' class='center'><?php if($_GET['view'] == "grpgusers") { echo "MS"; } else { echo "GD"; } ?> Emails</td>
			</tr>
			<tr>
                <th width='5%'>ID</th>
                <th width='35%'>Username</th>
                <th width='48%'>Email</th>
				<th width='12%'>Action</th>
            </tr><?php
            if($_GET['view'] == "grpgusers") {
				$db->query("SELECT id, username, email FROM grpgusers ORDER BY id ASC " . $pages->limit);
			} else {
				$db->query("SELECT * FROM gdemails ORDER BY emailid ASC " . $pages->limit);
			}
			$db->execute();
                $rows = $db->fetch_row();
                foreach ($rows as $row) {
                    ?><tr>
						<td><?php echo $row['id']; ?></td>
                        <td><?php echo $row['username']; ?></td>
                        <td><?php echo $row['email']; ?></td>
                        <td><?php echo '[Delete]'; ?></td>
                    </tr><?php
                }
            ?></table>
			<br />
			<div class='paginate'><?php echo $pages->display_pages(); ?></div>
</td></tr><?php
require_once __DIR__ . '/footer.php'; 

m missing something dumb so be gentle with me.

Edited by NICON
Link to comment
Share on other sites

Quite simple my mail is failing to send. The $_POST variable is not echo ing after being reassigned to $message and $email is not appearing either to satisfy the mail() function.

 

 

how do you know the email is not being sent? what exact symptom, error, or output are you getting from your code and what output did you expect?

 

where in the posted code are you echoing the message at?

 

how do you know that the $email isn't somehow satisfying the mail() function. there are many levels of satisfaction and unless we know your standard, we are left guessing what that statement means.

 

short-answer: were are not there with you and don't know what you saw when you ran your code. the information you supply must concisely communicate what did happened, what should have happened, and for the case of echoing things in the code, post that code, not some other code.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.