Page 1 of 1

SMTP Script

Posted: Wed May 17, 2006 10:55 am
by NiGHTFiRE
Hey,
I've done a SMTP script and this is it:

Code: Select all

<?

error_reporting(E_ALL);

include "../conn.php";

require("D:\www\Apeal\mail\david\phpmailer\class.phpmailer.php");



ini_set("max_execution_time","9999");

ignore_user_abort(true); 



#################

#   VARIABLAR   #

#################

$text			= $_POST['meddelande'];

$subject		= $_POST['subject'];

$sender			= $_POST['sender'];

$user			= $_POST['user'];

$datum			= $_POST['datum'];

$tid			= $_POST['tid'];

$NewReplyTo		= $_POST['sender'];

$avser			= 'skarpt';

$databas_arkiv	= "test_arkiv";

$databas_epost	= "test_mailadresser";

##################

#   /VARIABLAR   #

##################

 

 

if($text!=""){

$sql = "SELECT epost FROM $databas_epost WHERE aktiv='yes'";

$result = mysql_query($sql) OR DIE(mysql_error());

$rows = mysql_num_rows($result); //Hur många aktiva subscribers |Borg

 

// -- nollställning av räknare och innehållsvariabler

$count = 0;

$fails = 0;

$recepient = "";

$message2 = "<a href=\"http://www.websitensnamn.net/tabort.php?id={$epost}?databas={$databas_epost}\">Vill du inte längre få detta nyhetsbrev. Klicka här</a>\r\n";// ..something



// Nu loopar vi ut alla fjån

while ($row = mysql_fetch_array($result)){

$recepient=$row['epost'];



$mail = new PHPMailer();			//Run the class once

$mail->IsSMTP();					// telling the class to use SMTP

$mail->Host = "127.0.0.1";			// SMTP server 127.0.0.1/localhost

$mail->IsHTML(true);				

$mail->From = "$sender";			//From whom

$mail->AddAddress('$recepient');	//To whom

$mail->Subject = "$subject";		//Subject

$mail->Body = $text."\n". $message2;//The <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>

$count++;							//For our summery (Count ALL mails)





if($mail->Send())					//Is the mail sent or not?

{

	$check ='Ja';					//What is that variable for?

}

else 

{

	$check = 'Nej';					//What is that variable for?

	$fails++;						//For our summery (Count ALL failed mails)

}

}

 

echo "<table width=\"924\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" background=\"img/hem_bak.gif\">

    <tr>

    <td width=\"40\">&nbsp;</td>

    <td width=\"876\"><font face=\"Verdana\" size=\"1\"><br><br><b>Nu är vi klara!<br>Totalt ".$fails." utav ".$count."mail misslyckades, resten har hittat hem till sin nya ägare.<br></b></font></td>

    <td>&nbsp;</td>

  </tr>

  <tr>

    <td colspan=\"3\"><img src=\"img/ner.gif\" width=\"924\" height=\"31\" alt=\"hem_ner\" /></td>

  </tr>

</table>";

}

?>
But i get an error:
Notice: Undefined variable: epost in D:\www\Apeal\mail\david\mail_send.php on line 36
And i don't even have any thing with epost on line 36. So if someone can find the error i'll apreciate it

Posted: Wed May 17, 2006 11:14 am
by Burrito
check this line you should:

Code: Select all

$message2 = "<a href=\"http://www.websitensnamn.net/tabort.php?id={$epost}?databas={$databas_epost}\">Vill du inte längre få detta nyhetsbrev. Klicka här</a>\r\n";// ..something

Posted: Wed May 17, 2006 12:12 pm
by NiGHTFiRE
What's wrong with that line?

Posted: Wed May 17, 2006 1:01 pm
by Burrito
defined $epost above it you did not.

Posted: Wed May 17, 2006 1:49 pm
by Chris Corbyn
This line:

Code: Select all

require("D:\www\Apeal\mail\david\phpmailer\class.phpmailer.php");
Should be this:

Code: Select all

require("D:\\www\\Apeal\\mail\\david\\phpmailer\\class.phpmailer.php");
Because backslash is an escape character in itself.

Posted: Thu May 18, 2006 10:53 am
by NiGHTFiRE
Well i've fixed that now but it still doesn't email :S
Why?

Posted: Thu May 18, 2006 11:34 am
by Chris Corbyn
NiGHTFiRE wrote:Well i've fixed that now but it still doesn't email :S
Why?
Try changing the \n in $mail->body to \r\n. Does SMTP work on localhost using telnet? Perhaps the mail is being blocked as spam?

Posted: Fri May 19, 2006 12:34 am
by NiGHTFiRE
Didn't work when i changed it, yes SMTP works on telnet. It's not getting blocked by spam cause then it would atleast say that if mailed.