PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hey,
I've done a php codw where people should get emailed from a database and i get this error:
Warning: mail() [function.mail]: SMTP server response: 501 Syntax error in parameters or arguments to MAIL command in D:\www\Apeal\mail\david\mail_send.php on line 59
Emailet skickades till 'david.wibergh@gmail.com'
Notice: Use of undefined constant subject - assumed 'subject' in D:\www\Apeal\mail\david\mail_send.php on line 59
And this is my code:
<?php
session_start(); // Alltid överst på sidan
error_reporting(E_ALL);
// Kolla om inloggad = sessionen satt
if (!isset($_SESSION['sess_user'])){
echo "<script type='text/javascript'>
document.location.href = 'index.php';
</script>";
exit;
}
?>
<?php include '../meny.php'; ?>
<?php include '../meny_mail.php'; ?>
<?php
include "../conn.php";
#################
# VARIABLAR #
#################
$text = $_POST['meddelande'];
$subject = $_POST['subject'];
$sender = $_POST['sender'];
$user = $_POST['user'];
$datum = $_POST['datum'];
$tid = $_POST['tid'];
$NewReplyTo = $_POST['sender'];
$avser = 'skarpt';
$tabell_arkiv = "test_arkiv";
$tabell_epost = "test_mailadresser";
$message2 = "<a href=\"http://www.nippe.net/test/lindahl/briefings/tabort.php?id=22?databas={$tabell_epost}\">Vill du inte längre få detta nyhetsbrev. Klicka här</a>\r\n";
##################
# /VARIABLAR #
##################
if(($text == "") || ($subject == "") || ($sender == "")) {
echo "<script type='text/javascript'>
document.location.href = 'http://www.apeal.se/mail/mail_form.php';
</script>";
exit;
} else {
$epost = "select epost from $tabell_epost where aktiv='yes'";
$result = mysql_query($epost);
$rows = mysql_fetch_array($result);
// To send HTML mail, the Content-type header must be
$MailHeader = 'MIME-Version: 1.0' . "\r\n";
$MailHeader .= 'Content-type: text/html; charset=iso-8859-9' . "\r\n";
//fungerar inte $MailHeader .= 'bcc:' . "\r\n";
$MailHeader .= 'From: '. $sender. '<'. $sender . '>'. "\r\n";
$MailHeader .= 'Reply-To: '.$NewReplyTo.' <'.$NewReplyTo.'>'. "\r\n";
$MailHeader .= 'Date: '.date('r'). "\r\n";
$MailHeader .= 'Message-ID: <'.date('YmdHis').'info@'.$_SERVER['SERVER_NAME'].'>'. "\r\n";
$MailHeader .= 'X-Mailer: PHP/' . phpversion(). "\r\n";
$MailHeader .= 'X-Priority: 3' . "\r\n";
//$Mailheader .= 'Return-path: '. $sender. '<'. $sender . '>'. "\r\n";
$MailHeader .= 'Importance: Normal'."\r\n";
$message1 = "<a href=\"http://www.nippe.net/test/lindahl/briefings\">Kan du inte läsa detta nyhetsbrev. Klicka här</a><br>\r\n";
while ($row = mysql_fetch_array($result)) {
$email_adrr = $row['epost'];
mail($email_adrr, stripslashes($_POST[subject]), stripslashes($text), $MailHeader);
echo "Emailet skickades till '$email_adrr'";
}
}
?>
I've also looked up the SMTP replies and seen that error 501 means: 501 Syntax error in parameters or arguments
So i've looked if I made the correct mail form and i think i've done it. I've also looked on diffrent places but can't find why.
Thanks a lot and I hope i'm not doing any easy error that's just a waste of your time.
Thanks
Howdy folks,
The problem is more likely to be the fact that you have defined a result handler to the query twice.
Once right after the query and again in the loop.
This will stop the code from running the second query and therfore won't populate the $email_adrr variable - hence the error of parameters.
Remove the mysql_fetch_array from after the query and leave the one in for the loop.
Just as a side note, I generally tend to sanitize the data before it gets as far as the functions such as mail. so do you stripslashes on the variables when they are registered. It doesn't make a great deal of difference but it is tidy