Jump to content

PHP Mailer


ninedoors

Recommended Posts

I am having a problem with the phpmailer.  I have been using the following code to try and send emails to all the people in my database.  But it isn't really working properly, I have been trying to test it with my own email addresses one at a time.  The problem is that when I try and send an email to [email protected] or me @rogers.com it isn't sending the email although I am getting the 'Message has been sent' from the bottom of my code.  As you can see I am using the email [email protected] to send the emails from.  When I send an email to [email protected] it goes through and works.  I can't figure it out and any help would be great. Here's the script I am using:

<?php
require("class.phpmailer.php");
require("phpmailer.lang-en.php");
$mail = new PHPMailer();

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.barriemenshockey.com"; // SMTP server
$mail->SMTPAuth = "true"; // turn on SMTP authentication
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "*********"; // SMTP password

include 'mailconfig.php';

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$mail->From = "[email protected]";
$mail->FromName = "Barrie Mens Hockey League";

$query = "SELECT name, email FROM Test";
$result = mysql_query($query);

while ($row = mysql_fetch_array ($result))	{
// HTML body
$body  = "Hey " . $row['name'] . ", <p>";
$body .= "Something I would like to write<p>";
$body .= "Sincerely, <p>";
$body .= "Nick and Rob";

//non-HTML body
$textbody  = "Hey " . $row['name'] . ", \n\n";
$textbody .= "Some thing I would like to write\n\n";
$textbody .= "Sincerely, \n";
$textbody .= "Nick and Rob";


$mail->Subject = "Final BMHL dues";
$mail->Body = $body;
$mail -> AltBody = $textbody;
$mail->AddAddress($row['email']);
$mail->WordWrap = 50;

if(!$mail->Send())
{
   echo "There has been a mail error sending to " . $row["email"] . "<br>";

   echo 'Mailer error: ' . $mail->ErrorInfo;
}
else
{
   echo 'Message has been sent.';
}
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
}

?> 

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/72207-php-mailer/
Share on other sites

Does your server allow you to do mail relay?  Many servers only let you send to foreign hosts if the sender is a valid user.  You said you are sending @hotmail.com... I would never allow that on my server... SPAMMERS are getting harder to combat, and mail relay is an often exploited configuration.

Link to comment
https://forums.phpfreaks.com/topic/72207-php-mailer/#findComment-364107
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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