SMTP Script

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!

Moderator: General Moderators

Post Reply
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

SMTP Script

Post 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
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Post by NiGHTFiRE »

What's wrong with that line?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

defined $epost above it you did not.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Post by NiGHTFiRE »

Well i've fixed that now but it still doesn't email :S
Why?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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?
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Post 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.
Post Reply