Jump to content

PHPMailer sends email only to Outlook


B_CooperA

Recommended Posts

He'res my function for sending a reminding email every time user has pressed the "Remind" -button. I'm testing it out with two different mail providers, Gmail and Outlook and it does work with Outlook but don't send any emails to my Gmail.. It did work when I was using the old mail() - function, but when I moved to PHPMailer, it stopped working. Here's my code:

public function remindUser() {

$query = "SELECT * FROM users 
INNER JOIN user_events ON user_events.userID = users.user_id 
INNER JOIN events ON events.event_id = user_events.eventID 
WHERE events.event_id = :event_id";

	$stmt = $this->connect->prepare($query);
	$stmt->execute(array(

		':event_id' => $_POST['event_id']

		));

	$rows = $stmt->rowCount();

	if($rows == 0) {
		// Jos ei onnistu, siirretään käyttäjä Googleen (?)
		$this->error[] = "Tapahtumaan ei ole osallistunut kukaan";

	} else {

while($this->row = $stmt->fetch(PDO::FETCH_ASSOC)) {

// Osoitteet
$addresses[] = $this->row['email'];
$to = implode(", ", $addresses);

// Sähköpostiviestin aihe
$subject = "Tapahtuman ".$this->row['event_name']. " muistutusviesti sivustolta SportieTown";

// HTML - pohja sähkäpostille

$template = "<html><body>
<div class='header' style='background-color: #f67004; width: 700px; height: 60px;'>
<img src=\"cid:logoimg\"  style='float: right; margin-right: 20px;' />						
						
<h1 style='color: #ffffff; float: left; margin-left: 20px;''>Hei, ".$this->row['name']."!</h1></div>\n\n
						
<p style='color: #333333; font-size: 13px; font-family: Verdana; float:left;'>
Tämä on automaattinen viesti, joka lähetettiin SportieTown-käyttäjän <b>".$_SESSION['name']."n</b> toimesta\n\n
						
<p style='color: #333333; font-size: 11px; font-family: Verdana; float:left;'>
SportieTownin käyttäjä ".$_SESSION['name']. " halusi muistuttaa sinua tapahtumasta <b>".$this->row['event_name']."</b>, joka järjestetään".date("d.m.Y", strtotime($this->row['event_date']))." kello " .$this->row['event_time']. "\n
						
<p style='color: #333333; font-size: 11px; font-family: Verdana; float:left;'><i>Muistathan siis osallistua tapahtumaan\n\n
Terveisin, SportieTownin väki</i></p>
</body></html>";
	
	require("phpmailer/class.phpmailer.php");
	$mail = new PHPMailer();
	$mail->IsMail();

	$mail->IsHTML(true);
	$mail->AddAddress($to);
	$mail->AddEmbeddedImage('logo-small.png', 'logoimg', 'logo-small.png'); 
	$mail->Subject = $subject;
	$mail->Body = $template;

	if(!$mail->Send())
	{
	  header("location:http://www.google.fi");
	}
	else
	{
	  header("location:profile.php?id=".$_SESSION['user_id']."");
	}

Link to comment
https://forums.phpfreaks.com/topic/282661-phpmailer-sends-email-only-to-outlook/
Share on other sites

Yeah, the actual problem is not with the Gmail.. It's just sending the email to one user.. I pasted my code again in here, since I can't edit my original post. So what I'm doing wrong?

public function remindUser() {

$query = "SELECT * FROM users 
INNER JOIN user_events ON user_events.userID = users.user_id
INNER JOIN events ON events.event_id = user_events.eventID 
WHERE events.event_id = :event_id";

	$stmt = $this->connect->prepare($query);
	$stmt->execute(array(

		':event_id' => $_POST['event_id']

		));

	$rows = $stmt->rowCount();

	if($rows == 0) {
		// Jos ei onnistu, siirretään käyttäjä Googleen (?)
		$this->error[] = "Tapahtumaan ei ole osallistunut kukaan";

	} else {
		
		while($this->row = $stmt->fetch(PDO::FETCH_ASSOC)) {
				
		require("phpmailer/class.phpmailer.php");
		$mail = new PHPMailer();
		// Osoitteet
			
		$addresses[] = $this->row['email'];
		$to = implode(",", $addresses);
		


// Sähköpostiviestin aihe
$subject = "Tapahtuman ".$this->row['event_name']. " muistutusviesti sivustolta SportieTown";

// HTML - pohja sähkäpostille
$template = "<html><body>
<div class='header' style='background-color: #f67004; width: 700px; height: 60px;'>
<img src=\"cid:logoimg\"  style='float: right; margin-right: 20px;' />						
						
<h1 style='color: #ffffff; float: left; margin-left: 20px;''>Hei, ".$this->row['name']."!</h1></div>\n\n
						
<p style='color: #333333; font-size: 13px; font-family: Verdana; float:left;'>
Tämä on automaattinen viesti, joka lähetettiin SportieTown-käyttäjän <b>".$_SESSION['name']."n</b> toimesta\n\n
						
<p style='color: #333333; font-size: 14px; font-family: Verdana; float:left;'>
SportieTownin käyttäjä ".$_SESSION['name']. " halusi muistuttaa sinua tapahtumasta <b>".$this->row['event_name']."</b>,joka järjestetään".date("d.m.Y", strtotime($this->row['event_date']))." kello " .$this->row['event_time']. "\n
						
<p style='color: #333333; font-size: 11px; font-family: Verdana; float:left;'><i>Muistathan siis osallistua tapahtumaan\n\n

Terveisin, SportieTownin väki</i></p>
</body></html>";
	

	$mail->IsMail();
	$mail->IsHTML(true);
	$mail->AddEmbeddedImage('images/logo-small.png', 'logoimg', 'images/logo-small.png'); 
	$mail->AddAddress($to);
	$mail->Subject = $subject;
	$mail->Body = $template;

	if(!$mail->Send())
	{
	  header("location:http://www.google.fi");
	}
	else
	{
	  header("location:profile.php?id=".$_SESSION['user_id']."");
	}

	header("location: profile.php?id=".$_SESSION['user_id']."");
	}
	return count($this->error) ? 0 : 1;
	}
}

I don't use phpMailer, but it sounds like you never sent anybody a message with a gmail account.

Have you ever tried some debugging steps to debug the output of this $to variable?
Something like:

$to = implode(", ", $addresses);

echo '<pre>'.print_r($to, true).'</pre>';

Also, what happens if you try to set two or more outgoing messages to different mail servers in the AddAddress() method?
 

$mail->AddAddress("[email protected]","[email protected]");

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.