s.w.vanderlaan Wed Apr 15, 2009 3:02 am
Hi,
I have VAMP installed and also on a live server, both with Apache 2.2, PHP 5.2 and MySQL 5.2.
I read yesterday something on how to use the mail function in php
I did indeed change it a little, but only in the looks. Though I also changed the function sendbulkmail, but only so that I can send HTML-mail. When I use the original, it still giving the same error.
Now I know, I don't have an e-mailserver installed on my VAMP (don't know how), but of course my webserver does have an e-mailserver, which works fine.
I've pasted my adapted code below.
- Code:
<?php
/**
* sendbulkmail.php
*
*
* Originally written by: Fred-Eric Lafaille, fred-eric@lafaille.ca; Last Updated: March 6 2009
*
* Adapted by: Sander W. van der Laan
* Last updated: April, 14 2009
*
*/
require_once("../_includes/session.php");
function GetEmailList(){
global $database;
$q = "SELECT email FROM ".TBL_USERS;
$result = $database->query($q);
$num_rows = mysql_numrows($result);
if(!$result || ($num_rows < 0)){
die ("Error gathering e-mail list.");
return;
}
if($num_rows == 0){
die ("Database table empty.");
return;
}
/* Display table contents */
for($i=0; $i<$num_rows; $i++){
$email = mysql_result($result,$i,"email");
echo "{$email}; ";
}
}
function sendbulkmail($email, $subject, $body){
$from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">";
$email = trim($email);
mail($email, $subject, "<html><body>".$body."</body></html>",
"".$from."\n" .
"MIME-Version: 1.0\n" .
"Content-type: text/html; charset=iso-8859-1");
return $email;
}
/**
* User not an administrator, redirect to main page
* automatically. */
if(!$session->isAdmin()){
header("Location: ../index.php");
}
else
{
/**
* Administrator is viewing page, so display all * forms. */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The Aristotélēs Project</title>
<link href="../_styles/styles_oneColFixCtrHdr.css" rel="stylesheet" type="text/css" />
<script src="spryassets/SpryMenuBar.js" type="text/javascript"></script>
<script src="../_scripts/js_today.js" type="text/javascript"></script>
<script type="text/javascript">
_editor_url = "http://www.waldamargroup.com/aristoteles/xinha/" // (preferably absolute) URL (including trailing slash) where Xinha is installed
_editor_lang = "en"; // And the language we need to use in the editor.
_editor_skin = "silva"; // If you want use a skin, add the name (of the folder) here
</script>
<script src="http://www.waldamargroup.com/aristoteles/xinha/XinhaCore.js" type="text/javascript"></script>
<script src="http://www.waldamargroup.com/aristoteles/xinha/my_config.js" type="text/javascript"></script>
<link href="../spryassets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
</head>
<body class="oneColFixCtrHdr">
<div id="today">
<?php include ("../_includes/today.inc"); ?>
</div>
<div id="container">
<div id="header">
<img src="../images/logo.png"/>
<?php require_once ("../_includes/menuadmin.inc"); ?>
<img src="../images/menugradient.png"/>
<!-- end #header --></div>
<div id="mainContent">
<h1>Send E-mail to users</h1>
You can write your e-mail using the form below and send it to all the users of The Aristotélēs Project. Feel free to delete any of the selected e-mail addresses of any users.<br/><br/>
<?php
if (!isset($_REQUEST['alreadysend'])){
?>
<form action="<?= $_SERVER['PHP_SELF']?>" method="POST">
<label for="to"><i>Send to:</i></label><br/>
<textarea name="to" id="to" class="textfield" style="width:90%" cols="50" rows="5" /><?= GetEmailList();?></textarea><br/>
<label for="title"><i>Subject:</i></label><br/>
<input type="text" name="subject" id="subject" class="textfield" style="width:90%" value="Your subject here, please" /><br />
<label for="body"><i>Message</i></label><br/>
<textarea name="body" id="body" class="textfield" style="width:90%" cols="50" rows="20" />Write your e-mail message here.</textarea>
<input type="hidden" value="1" name="alreadysend" /><br />
<input type="submit" name="Submit" id="Submit" value="Send e-mail" />
</form>
<?php
} else
?>
<font color="#FF9900">
<?php
{
$emailarray = explode(';', $_REQUEST['to']);print_r ($emailarray);
print '<br />Successfully send mail to these users.<br />';
foreach ($emailarray as $key => $email) {
if($email != " ")
print '['.sendbulkmail($email, $_REQUEST['subject'], $_REQUEST['body']). ']<br />';}
}
?>
<input type="button" value="Send an other mail" onClick="top.location.replace('<?=$_SERVER['PHP_SELF']?>');"/>
<?php
}?>
</font>
<!-- end #mainContent --></div>
<div id="footer">
<?php require_once('../_includes/footer.inc');?>
<!-- end #footer --></div>
<!-- end #container --></div>
<div id="whologgedin">
<?php include ("../_includes/whologgedin.inc"); ?>
</div>
<script type="text/javascript">
<!--
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"../SpryAssets/SpryMenuBarDownHover.gif", imgRight:"../SpryAssets/SpryMenuBarRightHover.gif"});
//-->
</script>
</body>
</html>
So, maybe you can see what it is about these messages, when I have NOT sent any mail yet:
- Array ( [0] => )
- Successfully send mail to these users.
- No recipient addresses found in header []
I think the last message has to do with the sendbulkmail function, the PHP-machine doesn't "see" the recipient addresses in the header of the e-mail, but ofcourse that's the maillist ($email). How do you figure that?
Also, I was wondering what
<?= means in a php statement like
<?=$_SERVER['PHP_SELF']?>.
Hoping you or Fred-Eric can help?
Ciao,
Sander