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 me@hotmail.com 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 help@barriemenshockey.com to send the emails from.  When I send an email to me@barriemenshockey.com 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 = "help@barriemenshockey.com"; // 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 = "info@barriemenshockey.com";
$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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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